Skip to content
Advertisement

File is not sort after sort

I have a problem with sorting my file. My file look like this

geom-10-11.com 1 geom-1-10.com 9 geom-1-11.com 10 geom-1-2.com 1 geom-1-3.com 2 geom-1-4.com 3 geom-1-5.com 4 geom-1-6.com 5 geom-1-7.com 6 geom-1-8.com 7 geom-1-9.com 8 geom-2-10.com 8 geom-2-11.com 9 geom-2-3.com 1 geom-2-4.com 2 geom-2-5.com 3 geom-2-6.com 4 geom-2-7.com 5 geom-2-8.com 6 geom-2-9.com 7 geom-3-10.com 7 geom-3-11.com 8 geom-3-4.com 1 geom-3-5.com 2 geom-3-6.com 3 geom-3-7.com 4 geom-3-8.com 5 geom-3-9.com 6 geom-4-10.com 6 geom-4-11.com 7 geom-4-5.com 1 geom-4-6.com 2 geom-4-7.com 3 geom-4-8.com 4 geom-4-9.com 5 geom-5-10.com 5 geom-5-11.com 6 geom-5-6.com 1 geom-5-7.com 2 geom-5-8.com 3 geom-5-9.com 4 geom-6-10.com 4 geom-6-11.com 5 geom-6-7.com 1 geom-6-8.com 2 geom-6-9.com 3 geom-7-10.com 3 geom-7-11.com 4 geom-7-8.com 1 geom-7-9.com 2 geom-8-10.com 2 geom-8-11.com 3 geom-8-9.com 1 geom-9-10.com 1 geom-9-11.com 2

So I used sort -k1.6 -k2 -n and I got

geom-1-2.com 1 geom-1-3.com 2 geom-1-4.com 3 geom-1-5.com 4 geom-1-6.com 5 geom-1-7.com 6 geom-1-8.com 7 geom-1-9.com 8 geom-1-10.com 9 geom-1-11.com 10 geom-2-3.com 1 geom-2-4.com 2 geom-2-5.com 3 geom-2-6.com 4 geom-2-7.com 5 geom-2-8.com 6 geom-2-9.com 7 geom-2-10.com 8 geom-2-11.com 9 geom-3-4.com 1 geom-3-5.com 2 geom-3-6.com 3 geom-3-7.com 4 geom-3-8.com 5 geom-3-9.com 6 geom-3-10.com 7 geom-3-11.com 8 geom-4-5.com 1 geom-4-6.com 2 geom-4-7.com 3 geom-4-8.com 4 geom-4-9.com 5 geom-4-10.com 6 geom-4-11.com 7 geom-5-6.com 1 geom-5-7.com 2 geom-5-8.com 3 geom-5-9.com 4 geom-5-10.com 5 geom-5-11.com 6 geom-6-7.com 1 geom-6-8.com 2 geom-6-9.com 3 geom-6-10.com 4 geom-6-11.com 5 geom-7-8.com 1 geom-7-9.com 2 geom-7-10.com 3 geom-7-11.com 4 geom-8-9.com 1 geom-8-10.com 2 geom-8-11.com 3 geom-9-10.com 1 geom-9-11.com 2 geom-10-11.com 1

But when I tried use uniq -f1 or sort -k1.6 -k2 -n -u I got same long sorted output. So I used sort -k1.6 -k2 -n -c and get message that this file is disordered

(sort: glist2:2: disorder: geom-1-2.com 1).

I tried use just sort -k2 -n -u but got

geom-10-11.com 1 geom-1-3.com 2 geom-1-4.com 3 geom-1-5.com 4 geom-1-6.com 5 geom-1-7.com 6 geom-1-8.com 7 geom-1-9.com 8 geom-1-10.com 9 geom-1-11.com 10

That is not what I need, I need to have

geom-1-2.com 1 geom-1-3.com 2 geom-1-4.com 3 geom-1-5.com 4 geom-1-6.com 5 geom-1-7.com 6 geom-1-8.com 7 geom-1-9.com 8 geom-1-10.com 9 geom-1-11.com 10

So I need to have at begening geom-1-X and not geom-10-X. It would be great use juste uniq because I have more bigger files with more geometries (about thousands of lines) but with same structure. Thank you for your answers.

Advertisement

Answer

You can use this:

grep -E '^geom-1-' file | sort -k1.8n

grep is filtering the lines you want. sort is sorting numerically the first field starting at the 8th character.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement