bash: setting tab field separator with variable
Declare it using ANSI-C quoting:
sep=$'\t'
And call it as "$sep"
, quotes are important to preserve the literal meaning:
sort -t "$sep" file.txt
Example:
$ cat file.txt foo barspam eggabc def$ sep=$'\t'$ sort -t $sep file.txt sort: multi-character tab ‘file.txt’$ sort -t "$sep" file.txt abc deffoo barspam egg
Also note that, to get rid of the ambiguity with the environment variables i have used lowercase characters for the variable name, unless you have a very good reason you should do so too.
Use the keys [CONTROL]+[V] before pressing [TAB] to introduce the tab char.
echo "a b c" |cut -d" " -f2
b
Be careful if you copy paste the code, as the tabs may be lost, as they are lost in fact, in this post :-)