sc: the Venerable Spreadsheet Calculator
To save a file, press P followed by a filename, such as budget.sc. To save a plain-text representation, press W followed by a filename, such as budget.asc. I find these particularly useful, not only to paste into an e-mail quickly, but also to look through a set of spreadsheets easily.
You also can output other formats. For instance, to output a LaTeX table to paste into a paper, type S (for set) tblstyle=latex, followed by T (for table output) output.tex. The resulting LaTeX table, of course, also lends itself to unending options for pretty-fication by adding images, fonts, colors and whatnot. For me, plain text almost always is the most useful.
To exchange data with other spreadsheet programs, sc exports in a colon-delimited format. Unfortunately, this exports the results of formulas and not the formulas themselves, but it still can be useful.
You can output colon-separated files in sc by typing S (for set) tblstyle=0, followed by T (for table output) output.cln. Actually, 0 is the default tblstyle, so you need to do only the first step (S), if you selected another format previously (like LaTeX).
To import this in OpenOffice.org's OOCalc, open OOCalc, go to the Insert menu, and choose Select from file. Browse to your output.cln file and select it. You'll get an import screen with a Separator options section. For Separated by, choose Other, and type in a colon. Make sure all other Separated by options are deselected, or it won't work right.
Unfortunately, although sc can export other formats, it does not import them. However, you can work around that. One way is to start by getting CSV output. This should be an option for your on-line bank statement, for instance. From OOCalc, choose Save as→Text CSV format, and click Edit filter setting. If the next pop-up warns you about losing information in this format, click keep current format. In the field options pop-up, unselect Save cell contents as shown; otherwise, numeric values will be placed in quotes. For field delimiter, let's use :, as that's what sc outputs. Let's assume that import.csv is the name of the resulting file.
There probably are several ways to import this data into sc. For instance, sc offers advanced macros you might be able to use. However, I think the simplest way is to convert the CSV file into a valid sc format file. This is easy, because the sc format itself is simple, plain-text—another reason for my fondness of sc.
Listing 2. Python Script to Convert CSV Files to sc Format
#!/usr/bin/python
import sys
import string
if len(sys.argv) < 2:
print "Usage: %s infile [outfile] [delimiter_char]" % sys.argv[0]
sys.exit(1)
filename_in = sys.argv[1]
if len(sys.argv) > 2:
filename_out = sys.argv[2]
outfile = open(filename_out, 'w')
else:
outfile = sys.stdout
delimiter = ':'
if len(sys.argv) == 4:
delimiter = sys.argv[3][0]
print 'using delimiter %c' % delimiter
infile = open(filename_in, 'r')
letters = string.ascii_uppercase
text = ["# Produced by convert_csv_to_sc.py" ]
row=0
for line in infile.readlines():
allp = line.rstrip().split(delimiter)
if len(allp) > 25:
print "i'm too simple to handle more than 26 many columns"
sys.exit(2)
column = 0
for p in allp:
col = letters[column]
if len(p) == 0:
continue
try:
n = string.atol(p)
text.append('let %c%d = %d' % (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
row += 1
infile.close()
outfile.write("\n".join(text))
outfile.write("\n")
if outfile != sys.stdout:
outfile.close()
The Python script in Listing 2 simply walks over the CSV values one by one, writing out sc commands to insert text and numeric values. Note how easy it also would be to insert formulas, if CSV supported them. Run this script by typing:
python c.py import.csv import.sc
If your CSV file was separated by a character other than a colon, for instance, a comma, add the delimiter as the last option:
python c.py import.csv import.sc ','
Now, open the spreadsheet with:
sc import.sc
Voilà, your on-line bank statement or simple OpenOffice.org spreadsheet is now open in sc.
You can take this one step further and turn c.py into an automatic plugin. Be warned, however, that this support isn't perfect. To do so, place a copy into .sc/plugins/. Then, add a line to $HOME/.scrc that reads:
plugin "cln" = "c.py"
Now, any time you open a file in scn with a .cln extension using G (for get), it will be filtered through c.py, and sc will take its input from the plugin's standard output. Unfortunately, this support apparently was rarely used and is not well implemented. Specifying a .cln file on the command line (sc r.cln) will not invoke the plugin, so you must start sc with no files, and use the G command to load the file. Also, if you save the file later, it will use r.cln as the default filename but save an sc format file. So, if you use a plugin format, you'll need to specify a corresponding plugout script (let's call it cout.py) as well, and add a line to $HOME/.scrc that reads:
plugout "cln" = "cout.py"
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
- Non-Linux FOSS: libnotify, OS X Style
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- RSS Feeds
- Reply to comment | Linux Journal
2 hours 16 min ago - Reply to comment | Linux Journal
6 hours 16 min ago - Yeah, user namespaces are
7 hours 32 min ago - Cari Uang
11 hours 3 min ago - user namespaces
13 hours 57 min ago - yea
14 hours 22 min ago - One advantage with VMs
16 hours 51 min ago - about info
17 hours 24 min ago - info
17 hours 25 min ago - info
17 hours 26 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