Tab in bash script
How would i echo a tab? ive tried /t like in c++ and /TAB which i got from google somewhere. Neither worked unless im putting them in the wrong side of quotations.
this is what im trying to do: touch $Namepath/$1 #create file echo "\$TTL 3h" >> $Namepath/$1 echo "$1 IN SOA ns1.$1 coldbeaver.$1." >> $Namepath/$1 now i want to echo with a tab so ive tried: echo "\t blah blah" >> $Namepath and ive tried echo /t "blah blah" >> $Namepath but neither worked. Any help is appreciated |
You need to use -e to enable the use of special characters. man echo
For example.... echo -e "test \t\t test" |
'echo -e' works because of built-in functionality of echo. In general, if you want to insert tab in bash, you can force a literal tab by typing Ctrl-V TAB or the equivalent Ctrl-V Ctrl-I; this also works for other special characters.
This works, but is unreliable in scripts and copy-and-paste snippets, so I recommend the ultimate way using bash's escape character variables. They are described (poorly) in the manual; to get the tab you'd do $'\t'. Caution: unfortunately this doesn't work within the double-quoted strings, so if you need tabs and spaces, you have to do things like "a b"$'\t' |
^ Good advice, przemek. Also, I think this deserves a reward for oldest thread revival in history. :)
|
My pleasure, sir. I revived it because it came up high in Google search so I thought it'd be useful for others.
|
It was! Thanks.
|
To summarize the solutions given above, and to add one:
Code:
$ echo '[ ]' # enter a literal tab with <ctrl+v><tab> Finally, since <tab> is ascii 011 (octal) and x09 (hex), you can also use \011 or \x09 instead of \t. And from bash 4.2+ you can also use the unicode code point \u09. |
using tab as delimeter for the cut
Hi,
use this. it will work cut -d\t -f1,2 Ensure the input has the tabs not just the spaces. Hv Gd Time.. |
man cut
Code:
-d, --delimiter=DELIM and in your code, you were setting as t not tested.. but I think Code:
cut -d$'\t' |
tab as delimeter for the tab
Hi,
I tested.Both are working fine. cut -d\t as well as cut -d$'\t' As you said it could be redundant. (Any ways it could be useful for other special characters). thanks, Hv Gd time.. |
Code:
echo -e "t1\tt2\tt3" you need to retest |
Code:
$ echo $'a\tb' |
another resurrection of old post.
:) |
All times are GMT -5. The time now is 07:49 AM. |