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.
column command in Linux is used to display the contents of a file in columns. The input may be taken from the standard input or from the file. This command basically breaks the input into multiple columns. Rows are filled before columns.
Select the text you want to format. Select the Page Layout tab, then click the Columns command. A drop-down menu will appear. Select the number of columns you want to create.
It is very simple and easy to use command line utility. This command line utility converts the input file into multiple columns and you can convert the content into the columns based on any delimiter.
Specify a set of characters to be used to delimit columns for the -t option. Determine the number of columns the input contains and create a table. Columns are delimited with whitespace, by default, or with the characters supplied using the -s option. Useful for pretty-printing displays.
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.
This works to output a pretty print version of a tab delimited file
column -t -s $'\t' list-of-entries.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With