2

I need to arrange the below, in the shown order. First based on 1st column, secondarily based on 3rd column.

148672074   ABC 23.77
148672073   ABC 13.77
148672074   ABC 53.77
148672071   ABC 23.77
148672074   ABC 93.77
148672074   ABC 193.77

I need it like,

148672071   ABC  23.77
148672073   ABC  13.77
148672074   ABC 193.77
148672074   ABC  93.77
148672074   ABC  53.77
148672074   ABC  23.77

I used the below command.

sort -t "\t" -k1,1n -k3,3rn a.txt >b.txt

However, I'm getting the output as

148672071   ABC  23.77
148672073   ABC  13.77
148672074   ABC 193.77
148672074   ABC  23.77
148672074   ABC  53.77
148672074   ABC  93.77

Somebody Please tell me where I'm going wrong? And kindly give me the right command.

PS: The file I'm using is a TSV format file, exported from an excel sheet.

1 Answer 1

3

\t is recgnized as t, not as tab.

Instead of \t, press Ctrl + V, then Tab to denote tab character.

$ sort -t " " -k1,1n -k3,3rn a.txt
148672071   ABC 23.77
148672073   ABC 13.77
148672074   ABC 193.77
148672074   ABC 93.77
148672074   ABC 53.77
148672074   ABC 23.77

UPDATE

As fedorqui commented, you can also use $'\t':

$ sort -t $'\t' -k1,1n -k3,3rn a.txt
148672071   ABC 23.77
148672073   ABC 13.77
148672074   ABC 193.77
148672074   ABC 93.77
148672074   ABC 53.77
148672074   ABC 23.77
Sign up to request clarification or add additional context in comments.

2 Comments

You can also use -t $'\t'.
@fedorqui, Thank you for the comment. I'll add that to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.