Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Sorting on last field

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-31-2009
ganiel24 ganiel24 is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 6 May 2010, 8:23 PM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Sorting on last field

Hello
I am trying to sort on the last field and it seems to have lost ideas on what to do. the file am sorting looks like this

Code:
Tan\da\1223
hey\1234
two\three\think\4579

i want to sort on the last fields (1223, 1234 and 4579).
thank you

Last edited by Yogesh Sawant; 03-31-2009 at 01:09 PM.. Reason: added code tags
Sponsored Links
    #2  
Old Unix and Linux 03-31-2009
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 28 July 2015, 11:10 AM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,360
Thanks: 85
Thanked 164 Times in 150 Posts
Hammer & Screwdriver Here is one thouht


Code:
> cat file7
Tan\da\1223
hey\1234
two\three\think\4579
stuff\this\20566
those\12

> cat file7 | awk '{FS="\\" ; $0=$0 ; print $NF"|"$0}' | sort -n | cut -d"|" -f2
those\12
Tan\da\1223
hey\1234
two\three\think\4579
stuff\this\20566

Sponsored Links
    #3  
Old Unix and Linux 03-31-2009
ganiel24 ganiel24 is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 6 May 2010, 8:23 PM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you for your help, however when i tried
> cat file7 | awk '{FS="\\" ; $0=$0 ; print $NF"|"$0}' | sort -n | cut -d"|" -f2

It gave me the following error message:

awk: can't set $0
record number 1
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need immediate help with sorting!!! sasuke_uchiha Shell Programming and Scripting 9 08-05-2008 11:07 PM
Sorting : satyam_sat Shell Programming and Scripting 3 04-15-2008 12:30 PM
Retrieve 5th Field to Last Field !! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 03:20 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 05:39 AM
add increment field when first field changes azekry Shell Programming and Scripting 2 11-14-2005 03:21 PM



All times are GMT -4. The time now is 07:01 PM.