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!

grep - sort end of line

Status
Not open for further replies.

Tracy3e

Technical User
Jun 23, 2001
54
CA
Hi, I'm trying to do something weird I guess, because I can't figure out how to do it.

I have a file I'd like to sort. Instead of the sort looking at the field 1, I'd like the sort to look at the lines backwards, starting at the end of the line. I tried using the position or column sort but the problem is there are no columns and the lines are variable lengths so the results are not what I need.

Any ideas?
 
Any chance you could post some input samples, the rules and expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I've come up with some bogus sample data to be completely anonymous - does this help?

blahblabla134987145
blahblablablahblabla19874135
blahblablablahblablab789389074
blahblablablahblablablahblablablahblabla134571234
blahblablablahblablablahblabla13298744327
blahblablablahblablablahblabla487
 
So, I'll guess that you want to sort by the numerical part of end of line:
sed 'h;s!.*[^0-9]\([0-9]*\)$!\1!;G' /path/to/input |
awk '{x=$0;getline;print x,$0}' | sort -n |
sed 's![0-9]* !!' > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
wow, that worked for me, Stefan. Thank you both for your posts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top