LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk and sort for a chain of characters in a file (https://www.linuxquestions.org/questions/linux-newbie-8/awk-and-sort-for-a-chain-of-characters-in-a-file-4175436174/)

jachaja 11-07-2012 07:30 PM

awk and sort for a chain of characters in a file
 
Hi all,

I have a file with a lot of records similar to this:

023456AB2543999210709
022656AB2543999210409
024556AB2543999200709
024556AB2543999200909

I want to sort this file by using two parts of each record, for example: positions 3 to 4 like one field ascending and
positions 16 to 19 like other field descending.

The result:
022656AB2543999210409
023456AB2543999210709
024556AB2543999200909
024556AB2543999200709

how can i do it? It is possible using awk?

Thanks.

replica9000 11-08-2012 12:31 AM

Does it have to be awk? Why not sort?
Code:

cat yourfile | sort -k1.3,1.4n -k1.16,1.19r


All times are GMT -5. The time now is 08:46 PM.