99

I wanted to use the sort utility with the -t option to specify tab separators, but

sort -t "\t"

doesn't work.

Mark
  • 1,123

4 Answers4

115

Don't use double quotes.

sort -t $'\t'

Or I think Ctrl V inserts a Tab??

Edit:

http://www.gnu.org/s/bash/manual/html_node/ANSI_002dC-Quoting.html#ANSI_002dC-Quoting

surfasb
  • 22,896
78

Try Control-v, then Tab. If you see the cursor tab over to the right, it worked.

According to the comment by Mark you can also try Control-v and then Control-i.

L2G
  • 966
  • 5
  • 10
2

To put tab:

  • First press Ctr + v and

  • Then press tab key.


Example

Using above mentioned step adding tab enter image description here

Saving in file enter image description here

Final Output enter image description here


Reference: https://linuxjourney.com/lesson/cut-command

Nikhil
  • 131
0

You can also use printf:

sort -t "$(printf "\t")"

Not like $'\t', printf use double quotes which allow you to use environment variables, like below:

char="\t" # any source just plain text

sort -t "$(printf "$char")"

Single quote is static and not flexible, though it's simple, you can choose based on your requirement.