Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to use Unix column to format some text. I have fields delimited by tabs, but within each field there are also spaces. column delimits on white space (tabs and spaces). How can I make column only use tabs as the delimiter?

I was trying to specify tab as the delimiter using:

cat myfile | column -t -s"\t"
share|improve this question
column -t -s '\t'

would separate columns on \ and t characters.

column -s \t is the same as column -s t, as the backslash is interpreted as a quoting operator by the shell.

Here you want to pass a real TAB character to column. With ksh93, zsh, bash, mksh or FreeBSD sh:

column -ts $'\t'

Or enter a real tab character by typing Ctrl-V Tab at the shell prompt (within quotes or preceded by a backslash as the tab character is a token separator in the shell syntax just like space), or use "$(printf '\t')" (those double quotes needed to disable the split+glob operator as the tab character also happens to be in the default value of $IFS).

share|improve this answer
    
I had to do column -t -s $'\t' as bash seemed to think '\t' mean both \ and t, but $'\t' means a literal tab. Bash stinks – ThorSummoner Jun 21 at 22:11

The -t is for selecting the number of columns you want. Leaving this blank does not change anything. Also, you want white space after the -s so try this out:

cat myfile | column -s \t

share|improve this answer
    
Thanks. This is close to what I am looking for. However, now all the lines are merged onto one line. How can I keep each line on its own line? – turtle Nov 30 '12 at 10:09
    
By default, column fills rows before columns. You may be interested in pr – lurker Nov 30 '12 at 10:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.