Mohit Arora Mohit Arora - 7 months ago 22
Bash Question

Unix sorting mutiple conditions

I have a file in which there are numbers like

6.3.0.00.220
6.3.0.00.220C
6.3.0.00.220EH
6.3.0.00.221
6.3.0.00.221C
6.3.0.00.221EH


and so on

I want them to be groped/sorted as

6.3.0.00.220EH
6.3.0.00.221EH
6.3.0.00.220C
6.3.0.00.221C
6.3.0.00.220
6.3.0.00.221


Basically EH ones together in ascending then C together in ascending and then the rest in ascending.

I am trying
sort -k 1.10,1.14 -nr | sort -k 1.13 -r
but not getting the exact output.

Any help would be much appreciated. Thanks in advance

Answer

Will this work for you sort -r -t. -k5.4 somefile.txt