I am having difficulty with the Unix sort
command when tab delimited fields are introduced.
If a file test.txt
contains:
Hello (2)
Hello (1)
Hello
applying a sort:
sort test.txt
produces the output:
Hello
Hello (1)
Hello (2)
However, if a file test2.txt
contains tab separated fields:
Hello (2)\tFred
Hello (1)\tFred
Hello\tFred
where \t
is a tab character, applying a sort:
sort -t $'\t' -k 1,2 test2.txt
results in a different sort order.
Hello (1) Fred
Hello (2) Fred
Hello Fred
Is there a way to use the sort
command so that the tab delimited fields will be sorted like this:
Hello Fred
Hello (1) Fred
Hello (2) Fred