I'm trying to figure out the Linux column command this morning. To my mind, it does not work the way I think it should.
Here are the options to the column command as given on the man page:
column [-ntx] [-c columns] [-s sep] [file ...]
One of the mysteries of the column command for me is that the -c switch does not seem to work. Perhaps this is because my Linux is out of date. I'm still on Debian Lenny and today is March 6, 2014. This man page for column seems to suggest that the -c option works:
Column Man Page From October 2010
I love the description of the -c option. Being able to format a table to a specific number of characters is exactly what I want to be able to do! Unfortunately, I've never ever been able to make it work. The -c option does not seem to alter my output in any way no matter what I try.
Fortunately both the -s option and the -t option seem to work just fine under Debian. These options make the formatting of a table on a specified delimiter automatic.
The -t option seems to be the column commands most powerful feature. With -t, newlines are assumed to be new column rows. Thus, each non-blank line of input becomes a new row in your table. For example, 80 lines of input would translate into an 80-line table.
The best part of the -t option? It figures out the width of the columns for you. In other words, it shrink wraps. In this respect it is much like the <table> tag of HTML. All tabular data is shrink wrapped to fit as needed.
Here's a web page that describes the -n option. This option is necessary to create empty cells in your table:
Why does the column command not align columns properly?
Without the -n option, multiple delimiters consolidate to become just one delimiter. Of course, in some cases, this is the desired behavior.However, in a CSV file, two commas in a row often indicate an empty field. With the -n option present, the integrity of the empty field is respected and a empty table cell is created.
I suspect that over time, the behavior of the column command will become more and more standardized. The above link concerning aligning columns properly seems to suggest that the -n option is not universally available. It does not seem to be working under Slackware 9.0 (very old!).
If I could get the -c option to work, I'd be in heaven!
Ed Abbott
No comments:
Post a Comment