Sort file on columns and characters

Friday, December 28, 2012 0 Comments

Sort lines in file based on specific location character. Here I want to sort based upon the date in ascending order which is in 3rd column.
sltele Hoodie 24051988 d12Hdq
sltele Hoodie 07051987 d30Hdq
sltele Hoodie 07082011 d08Hdq
sltele Hoodie 09081961 d04Hdq
sltele Hoodie 20041962 d14Hdq
sltele Hoodie 20032000 d01Hdq
sltele Hoodie 13062002 d05Hdq
expected output:
sltele Hoodie 09081961 d04Hdq
sltele Hoodie 20041962 d14Hdq
sltele Hoodie 07051987 d30Hdq
sltele Hoodie 24051988 d12Hdq
sltele Hoodie 20032000 d01Hdq
sltele Hoodie 13062002 d05Hdq
sltele Hoodie 07082011 d08Hdq
Solution:
sort -n -k 3.8,3.12 -k 3.6,3.7 -k 3.4,3.5 < input_file

0 comments: