1
I want to sort file by first file, but the last character is the most important.
For example form file:
"AAAACTTTTT" 1 2
"AAAACAAAAA" 1 2 6 4
To:
"AAAACAAAAA" 1 2 6 4
"AAAACTTTTT" 1 2
I tried:
sort -k1,1 file
Of course it doesn't work, but I have no idea how I can do this. Could you help me? Mayby some secret flags?
You can try
rev
which reverse the line (delimiter is "\n"). So you can do it like thiscat file|rev|sort -k1,1 |rev
– makgun – 2016-06-02T16:23:31.023But now I don't know how many is filed and I can't pick field. – diego9403 – 2016-06-02T18:45:49.180
Sorry please more information (I have learnt English but not well) So I don't understand what you couldn't do – makgun – 2016-06-02T18:59:17.120
My English is very poor that can be a problem. I want to sort file contain, that kind of lines as I wrote and field to sort is 1 - "AAACTTT" and I want to sort this as "TTTCAAA". – diego9403 – 2016-06-02T19:03:50.007
Do you want to implement this for each field? – makgun – 2016-06-02T19:07:25.437
No only for this one. – diego9403 – 2016-06-02T19:15:55.943
Try this one
cat YourFile|sed 's/\([^ ]*\)\(.*\)/echo -e $(echo \1|rev)\2/g'|bash|sort |sed 's/\([^ ]*\)\(.*\)/echo -e $(echo \1|rev)\2/g'|bash
– makgun – 2016-06-02T19:41:12.553also you can try first part of it to understand how is it working. Firstly try
cat YourFile|sed 's/\([^ ]*\)\(.*\)/echo -e $(echo \1|rev)\2/g'|bash
secondly try thiscat YourFile|sed 's/\([^ ]*\)\(.*\)/echo -e $(echo \1|rev)\2/g'|bash|sort
this will give you how it is working – makgun – 2016-06-02T19:42:57.983I hope this will help you. The command look like very long but it is as fast as what you expected. There is also
awk
way but I am not enough good in awk. – makgun – 2016-06-02T19:49:03.233