Sample Header Ad - 728x90

How to print strings separated by TAB in bash?

11 votes
4 answers
37654 views
I am trying to print two string separated by a TAB. I have tried: echo -e 'foo\tbar' printf '%s\t%s\n' foo bar Both of them print: foo bar Where the whitespace between the two is actually 5 spaces (as per selecting the output with mouse in Putty). I have also tried using CTRL+V and pressing TAB when typing the command, with the same result. What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs? And the secondary question: why is bash expanding tabs into spaces? **Update**: Apparently, this is a problem of Putty: https://superuser.com/questions/656838/how-to-make-putty-display-tabs-within-a-file-instead-of-changing-them-to-spaces
Asked by Asu (225 rep)
Dec 15, 2018, 04:10 PM
Last activity: Jul 11, 2024, 09:06 AM