Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort help 2

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
please tell me how to sort file by last 5 characters in 2nd column?
 
Hi

That is not something you can solve with a couple of options added to [tt]sort[/tt]. The solution would be to copy the substrings you want to sort by to the beginning of the lines, sort them, then remove the added substrings.

To choose the easier solution for this, the question is if the first and/or second field is fixed length.

Feherke.
 
the second column has not fixed length.
the lenght of the second column is greather then 5.
the second column is combined of digits or digits with letters but the last 5 characters of the second column are always digits

for example, rows:
khsfs jsf23ls87234 lkjes
ljdfljg 872438744 lr9josslkfj
u9werowwr kh73y098234 j82u3roiwe
873yeuwh 8uwj87340 j8jerikfj98

I'd like to sort basing on red-marked digits...

 
Implementing feherke's idea:

Code:
awk '{print substr($2,length($2)-4),$0}' inputfile | sort -n -k 1,1 | cut -d' ' -f 2- > outputfile


Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top