The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ascii sorting in unix sais Shell Programming and Scripting 1 10-14-2008 08:23 AM
sorting an ascii file shes UNIX for Dummies Questions & Answers 2 10-08-2008 07:11 AM
Trouble sorting numbers embedded mycrew2008 Shell Programming and Scripting 4 04-04-2008 02:19 PM
Replace characters in a string using their ascii value roops Shell Programming and Scripting 2 03-04-2005 01:51 AM
String substitutions in ASCII files - SanjivNagraj UNIX for Dummies Questions & Answers 2 07-03-2002 05:58 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-02-2009
GKnight GKnight is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 35
sorting ASCII string containing numbers

I have the following output where I need to sort the second column numerically (starting with IBMULT3580-TD10 and ending in IBMULT3580-TD123)


Code:
Drv DriveName       
  0 IBMULT3580-TD13 
  1 IBMULT3580-TD18 
  2 IBMULT3580-TD14 
  3 IBMULT3580-TD10 
  4 IBMULT3580-TD11 
  5 IBMULT3580-TD17 
  6 IBMULT3580-TD117
  7 IBMULT3580-TD121
  8 IBMULT3580-TD15 
  9 IBMULT3580-TD112
 10 IBMULT3580-TD115
 11 IBMULT3580-TD111
 12 IBMULT3580-TD116
 13 IBMULT3580-TD12 
 14 IBMULT3580-TD113
 15 IBMULT3580-TD19 
 16 IBMULT3580-TD118
 17 IBMULT3580-TD16 
 18 IBMULT3580-TD123
 19 IBMULT3580-TD119
 20 IBMULT3580-TD120
 21 IBMULT3580-TD110
 22 IBMULT3580-TD114
 23 IBMULT3580-TD122

I'm trying to apply the sort, and the output is getting sorted, but not numerically:


Code:
`some_command` |sort -k 2

  3 IBMULT3580-TD10 
 21 IBMULT3580-TD110
 11 IBMULT3580-TD111
  9 IBMULT3580-TD112
 14 IBMULT3580-TD113
 22 IBMULT3580-TD114
 10 IBMULT3580-TD115
 12 IBMULT3580-TD116
  6 IBMULT3580-TD117
 16 IBMULT3580-TD118
 19 IBMULT3580-TD119
  4 IBMULT3580-TD11 
 20 IBMULT3580-TD120
  7 IBMULT3580-TD121
 23 IBMULT3580-TD122
 18 IBMULT3580-TD123
 13 IBMULT3580-TD12 
  0 IBMULT3580-TD13 
  2 IBMULT3580-TD14 
  8 IBMULT3580-TD15 
 17 IBMULT3580-TD16 
  5 IBMULT3580-TD17 
  1 IBMULT3580-TD18 
 15 IBMULT3580-TD19

I tried adding -n but it produces a rather weird output, seemingly in random order. Any suggestions how to sort this string numerically? I can't figure it out from the sort man page. TIA!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0