Bash: echo a tab

This entry was posted by on Wednesday, 15 June, 2011 at

When you’re scripting, you sometimes want nice ‘human readable’ results. Luckily, Bash’s echo command has some formatting tools.

Say you are printing a table, and want the columns separated by tabs:

n     nuppi       tati
1     0.23        0.001
2     0.22        0.004
3     0.20        0.005

Simply echo it like this:

echo -e n \\t nuppi \\t tati
... etc

You need the additional escape character (‘\’) in front of the standard tab-character \t, otherwise bash will think it is just a ‘t’.

A similar command in awk:

print n "\t" nuppi "\t" tati;


Leave a Reply