14

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.

4
  • 2
    can you post some sample input & output? Commented Aug 26, 2012 at 19:26
  • Note that column is 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. Commented Aug 27, 2012 at 0:02
  • 3
    If you want 3 columns of output, pr -l 1 -t -3 will get very close to what you wanted column to produce. For N columns, change the 3 to N; to specify a width, add -w 120 or whatever. Commented Aug 27, 2012 at 0:07
  • pr -l 1 -t -3 worked perfectly! Thanks, Jonathan! I think I don't quite understand the column command as illustrated below by ruakh. Commented Aug 27, 2012 at 0:40

2 Answers 2

13

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Great explanation with fully understanding of the real problem that the questioner encountered!
You hit it right on the head! Thanks for the great explanation!
6

This works to output a pretty print version of a tab delimited file

column -t -s $'\t' list-of-entries.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.