I'm trying to format a list of entries in bash, and am using the column command. However, the -t option defaults to using any whitespace as a delimiter, which does not work for the data I have (it contains spaces and tabs). I can't figure out how to get the -s flag to specify a newline character as the sole column delimiter.
2 Answers
In theory, to specify a newline, you can use the $'...' notation, which is just like '...' except that it supports C-style escape-sequences:
column -t -s $'\n' list-of-entries.txt
However, I don't really understand the purpose of this. A newline is the row delimiter, so a column-delimiter of $'\n' is equivalent to not having any column-delimiter at all:
column -t -s '' list-of-entries.txt
which means that the input will be treated as having only one column; so it's equivalent to not using column at all:
cat list-of-entries.txt
It seems like you actually don't want to use the -t flag, because the purpose of the -t flag is to ensure that each line of input becomes one line of output, and it doesn't sound like that's what you want. I'm guessing you want this:
column list-of-entries.txt
which will treat each line of list-of-entries.txt as a value to be put in one cell of the table that column outputs.
columnis available on Linux (and on Mac OS X 10.7.4). It is not necessarily available on other variants of Unix; it is not standardized by POSIX, for example.pr -l 1 -t -3will get very close to what you wantedcolumnto produce. For N columns, change the 3 to N; to specify a width, add-w 120or whatever.pr -l 1 -t -3worked perfectly! Thanks, Jonathan! I think I don't quite understand thecolumncommand as illustrated below by ruakh.