How to make spreadsheets in a Linux terminal

Last updated on December 12, 2020 by Adrien Brochard

If you are on a quest to get rid of your desktop environment and do everything from the console, well good luck with that. However, if you are a bit more serious, and would like to learn to do a new thing from the terminal, what about mastering spreadsheets?

Sure, LibreOffice or any office suite of your choice may do it very well in the first place, but sometimes using a pick up truck to go to the kitchen is not the most appropriate path. What I mean by that is that it happens that you may need to create a quick spreadsheet with just a few simple formulas, but nothing so complicated that you need all the power of a traditional office suite. Plus, if your system is a bit old, or if you are running a lot of applications in the background, you may have to wait a few dozens of seconds watching that splash screen load. On the other hand, a spreadsheet application in the console is fast, simple, and efficient. Among the magical software that will allow you to do that, I propose you sc, anagram for spreadsheet calculator.

Install sc on Linux

The sc package is available in the universe repo for Debian-based distros such as Debian, Ubuntu or Linux Mint, so installation on such systems is easy:

$ sudo apt-get install sc

On Arch Linux, check out the AUR.

For other distros, you can download its source, and build it.

Basic Usage of sc

As usual, the first screen is always the scariest. But good news: a lot of the shortcuts for sc are inspired by those of vim (or I guess it's bad news if you only know Emacs). So you can move around with the traditional hjkl keys:

Or just use the arrow keys if you are not afraid of being burn for heresy.

The second thing you might want to do in a spreadsheet is to enter some numerical value. I was a little thrown off at first because the insertion mode is a bit different here.

To enter a numerical value in the selected cell press =, then your value.

To enter some text instead, type <, then your text.

If you need to save your work at any time, use:

P[name].sc

to dump your work into a .sc file.

Conversely,

G[name]

will retrieve your work.

If you haven't guessed by yourself, the command q serves to quit the program.

But what we all want is to create some formulas. Just like in any traditional spreadsheet, start with = sign and refer to the other cells by their coordinate.

For example, to do the sum of the first two cells of the first row, do:

=A0+B0

To copy the content of a cell, get the cursor over it and press ma. Then go to an empty cell and do ca.

Finally, using the last technique and our earlier example, we can extend the formula to add the values of two adjacent cells with:

[#]ca

where [#] is just the number of cells we want to extend the formula to. As you may have noticed, this is just like in vim, where you do [#][command] to repeat a command a certain number of times. In our previous example:

3ca 

will extend the addition formula to the next 3 cells in the row, giving them the values of B0+C0, C0+D0, and D0+E0 respectively.

Advance Usage of sc

If you know your vim shortcuts, you will be able to make the most out of sc after a few experiments:

Use c to refer to a column. So dc and yc to delete and yank the current column respectively.

Use r to refer to a row. Same idea here, dr and yr to delete and yank the current row.

The command g to move to a particular line in vim also works in sc with the syntax:

g[coordinate of a cell]

For example, gC22 to go straight to the cell C22.

I said earlier that ma was to mark a cell. To be exact, it stores the content of the cell into the variable a, that you can then copy with ca. Alternatively, you can use any other letter to refer to a different variable: mb, mc, md, etc.

Check out more by typing ? at anytime from the interface.

To conclude, sc is another one of these programs which will make people debate over its utility. Is a console spreadsheet calculator obsolete, now that our computers are powerful enough to run LibreOffice or whatever? Or on the contrary, should we stick to the basics for simple tasks and not waste resources?

I also heard good things about oleo, which does sensibly the same thing, but never tried it myself. Is it a viable alternative to sc?

Anyway, let us know what you think in the comments.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean