Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Sorting on last field

Shell Programming and Scripting


Closed    
 
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 02: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: 29 November 2016, 1:38 PM EST
Location: Within two miles of a Dunkin donuts.
Posts: 2,413
Thanks: 102
Thanked 177 Times in 163 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

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-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 10:13 AM.