Sort file on columns and characters

28.12.12
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

No comments:

Post a Comment