sc: the Venerable Spreadsheet Calculator
Boy, there sure is a lot of software for Linux—a lot of software! Why, if you want a browser, you can choose between Firefox, Opera, Chrome, Galeon, Surf and many others. And, on the command line, wget, curl, Lynx, ELinks and more are available. For e-mail, options include Evolution, KMail, Balsa, and xmh; or on the command line, you can use mutt (my favorite), sup, pine, mh and countless more. Calendaring choices include the GNOME calendar, KDE calendar, xcal and Evolution; or, in a terminal, you can use the very powerful Remind or ccal, not to mention command-line interfaces to the Google calendar. And for spreadsheets, you've got OpenOffice.org's OOCalc, Gnumeric, KSpread and Xspread; or, in a terminal, you've got perhaps the best spreadsheet of all, sc, especially if you're a vi fan.
I've been using sc for years, mostly for budgeting and project planning. The earliest version I've found was posted to comp.sources.unix on August 18, 1987, by Robert Bond (see Resources), but that was already version 4.1. The post said it was previously known as vc, and that the original version was written by James Gosling (of Java language fame) in September 1982. Although documentation for sc can be hard to find, it does come with a decent man page and a neat tutorial, which you can load right into sc. It also uses the same file format as Xspread, so existing documentation on formulas in Xspread (which is more plentiful than for sc) also can be helpful.
If you use Debian or Ubuntu, just type sudo apt-get install sc. If your distribution doesn't have an sc package, see Resources for a link to the source. Start the program by typing sc in a terminal, and you'll see a screen that looks something like Listing 1. Because it's curses-based, you can run it over slow links, as well as inside screen, so that you can detach and re-attach from another terminal. There is a pretty detailed man page, which (in the Ubuntu package) points out that you can start up sc with a tutorial by doing this:
sc /usr/share/doc/sc/tutorial.sc
Actually, that isn't quite right. In Ubuntu, first you need to uncompress the tutorial:
sudo gunzip /usr/share/doc/sc/tutorial.sc.gz
Then start it.
Listing 1. Starting Up sc
sc 7.16: Type '?' for help.
A B C D E
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
If you prefer to get started immediately with some real data, here are some useful commands. Like vi, sc starts in a command mode. The vi movement keys, hjkl, move left, down, up and right among cells, as you would expect. To jump straight to cell D3, press gD3. You can begin entering a numeric value or formula using =. To interrupt a command gracefully, press Ctrl-G. See the Basic sc Usage in Command Mode sidebar for more simple commands.
Basic sc Usage in Command Mode
hjkl — vi keys motion (or cursor keys).
gB13 — go to cell B13.
ir, ic — insert row, insert column.
ma (mb, mc and so on) — “mark” cell as a (or b, or c and so on).
ca (cb, cc and so on) — copy contents previously marked with ma.
Ctrl-f, Ctrl-b — page up or down (also pgup, pgdown).
dr, yr, pr — delete row, yank row, put row.
dc, yc, pc — delete column, yank, put column.
dd, yd, pd — delete, yank, put a cell.
= — enter a numeric value (25 or F13-D14) or formula (@sum(A2:A145)).
< — insert left-justified text.
\ — insert centered text.
> — insert right-justified text.
x — remove cell.
W<filename.asc> — write plain-text file.
P<filename.sc> — write an .sc file.
G<filename.sc> — read (“get”) an .sc file.
Zr, Zc — zap (hide) row or column.
sr, sc — show row or column.
@ — force re-calculation.
e — edit a numeric value.
E — edit a string value.
To me, the three most important things about working with spreadsheets are the ease of adding new data, moving data and defining simple formulas that are re-calculated automatically. sc shines as far as the first two requirements with its vi-like command mode. It also does quite well with formulas. Check the on-line help for a sizable list of formulas, but the most common function in my experience is simple addition. This is no different in sc from any other spreadsheet.
To put the sum of the values in A3 through A10 into A12, go to cell A12, and type =@sum(A2:A10). To edit the formula, press e for edit, and you will be in command mode in the top line, editing the formula. Edit as you would in vi, and press Return to save the edited formula.
If you want to insert five more rows before row 5, go to cell A5, and type 5ir, which means “do 5 times: insert a row”. The formula (now in A17) will be updated automatically to read @sum(A2:A15). Now you can copy that formula into cell B17 by going to A17, typing ma, then going to B17 and typing ca. The formula will be updated automatically to read @sum(B2:B15).
If you want to highlight some specific data in the spreadsheet without actually having to delete rows, you can hide the uninteresting ones. This is called zapping in sc, and you do it by pressing Z followed by either r for row or c for column. (If you follow it with a Z instead, sc will assume you meant save and exit as ZZ does in vi.) You can un-hide by using S for show, followed again by r or c. Again, you can type 30Zr to zap 30 rows.
I've already mentioned the tutorial and detailed man page, but sc also has on-line help, which you can see by pressing ?. There, you will find settings you can toggle, ways to move the cursor, lists of financial functions and so on.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Speed Up Your Web Site with Varnish | Jun 19, 2013 |
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
- Speed Up Your Web Site with Varnish
- Containers—Not Virtual Machines—Are the Future Cloud
- Linux Systems Administrator
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Senior Perl Developer
- Technical Support Rep
- Non-Linux FOSS: libnotify, OS X Style
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- RSS Feeds
- It is quiet helping
2 hours 12 min ago - Technology
2 hours 29 min ago - Reachli - Amplifying your
3 hours 45 min ago - excellent
4 hours 34 min ago - good point!
4 hours 37 min ago - Varnish works!
4 hours 46 min ago - Reply to comment | Linux Journal
5 hours 16 min ago - Reply to comment | Linux Journal
7 hours 42 min ago - Reply to comment | Linux Journal
11 hours 41 min ago - Yeah, user namespaces are
12 hours 58 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Code patch with indentation corrected
Oops, I didn't realize the code would be reformatted. Should have used the right HTML tags to keep the indentation:
col = letters[column] if len(p) != 0: try: n = string.atof(p) text.append('let %c%d = %g' % (col, row, n)) except: if p[0] == '"': text.append('label %c%d = %s' % (col, row, p)) else: text.append('label %c%d = "%s"' % (col, row, p)) column += 1Improvement to script for empty cells
The script skips over empty cells as if they didn't exist. It's fine to not put anything in the .sc file for an empty cell, but one should move over to the next column so that empty cells are preserved. A fix is to replace the body of the "for p in allp" with this:
col = letters[column]
if len(p) != 0:
try:
n = string.atof(p)
text.append('let %c%d = %g' % (col, row, n))
except:
if p[0] == '"':
text.append('label %c%d = %s' % (col, row, p))
else:
text.append('label %c%d = "%s"' % (col, row, p))
column += 1
(I've aso applied the fix suggested in the previous comment.)
R.
Great article. Problem in Python script:(
Just on the day I started exploring sc on my Nanonote,
which was highligted in the same issue, I discovered this
really helpful article via web search. When my October
issue came in, I'm sure I saw the article, but it did
not catch my attention then:)
My quick review of sc revealed that there was no feature
to import from other formats. The Python script looked
like it solved the problem, but on my first test I found
that it treated all numbers containing a decimal point
as labels--not what I wanted. Changing the call
to string.atol() to string.atof() and changing
the format "let %c%d = %d' to 'let %c%d = %g'
solved the problem.
Now on to exploring sc on the Ben Nanonote. Thanks
for a timely article.
Delbert