Sorting on last field | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Sorting on last field

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 02:09 PM.. Reason: added code tags
Sponsored Links
    #2  
Old 03-31-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 17 November 2014, 3:07 PM EST
Location: Out running a Marathon.
Posts: 2,337
Thanks: 73
Thanked 155 Times in 144 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 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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-06-2008 12:07 AM
Sorting : satyam_sat Shell Programming and Scripting 3 04-15-2008 01:30 PM
Retrieve 5th Field to Last Field !! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 04:20 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 06:39 AM
add increment field when first field changes azekry Shell Programming and Scripting 2 11-14-2005 04:21 PM



All times are GMT -4. The time now is 09:33 PM.