Sponsored Content
Top Forums UNIX for Dummies Questions & Answers sorting ASCII string containing numbers Post 302303294 by GKnight on Thursday 2nd of April 2009 10:07:58 AM
Old 04-02-2009
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!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble sorting numbers embedded

Hi All, First time poster. I have a text file that as many entries like below (single line): egrep RspTime conlb.txt |more S(xxx.xxx.xxx.xxx:5050:UP) Hits(13358983, 2/sec, P) ATr(2) Mbps(0.07) BWlmt(0 kbits) RspTime(16.50 ms) ... I am trying to sort on the RspTime from highest to lowest... (4 Replies)
Discussion started by: mycrew2008
4 Replies

2. UNIX for Dummies Questions & Answers

sorting an ascii file

I would like to sort a large ascii file. Primary sort on the 1st column, and secondary sort on the second column. The file consists of 10 rows of header text and then thousands of rows with 6 columns. I want to sort all of the rows by the first column and second column. As an example, here is... (2 Replies)
Discussion started by: shes
2 Replies

3. Shell Programming and Scripting

ascii sorting in unix

Hi all i am facing a problem in sorting command. The script depending on the sorting command works fine only if ascii sorting is done. i need to know how to find out how to perform ascii sorting. sorting is case insensitive in my file has data in the following format. AA/BB/ AAA/BB\ also... (1 Reply)
Discussion started by: sais
1 Replies

4. UNIX for Dummies Questions & Answers

Sorting data in an ASCII file

Hi,,, is there anyway to sort the data that I have on an ASCII file, using unix? :confused::confused::confused: Thanks (2 Replies)
Discussion started by: cosmologist
2 Replies

5. UNIX for Dummies Questions & Answers

sorting numbers with sort -n

Looking for help for sort, I learned that for sorting numbers I use: sort -n but it seems that that is not enough when you have numbers like 0.2000E+7 for example, sort -n will not worry about the E+7 part, and will just sort the numbers like 0.2000. Exapmle: cat example.txt .91000E+07... (9 Replies)
Discussion started by: cosmologist
9 Replies

6. Shell Programming and Scripting

Sorting numbers containing symbols

hi all, i need help on sorting data. i have a file as below /home/oracle $ cat 234.txt +1234 -2356 -1001 +231 0023 -0987 +19000 65487 6 after sorting i want the output as below -2356 -1001 (2 Replies)
Discussion started by: mahesh1987
2 Replies

7. Shell Programming and Scripting

Sorting mixed numbers and letters

Hello, I have a file such as this: chr1 chr2 chr1 chr2 chr3 chr10 chr4 chr5 chrz chr1AI want to sort it, I use this command: sort -k1 -th -n testfilebut I get this output, how can I fix this? chr1 chr1 chr10 chr1A chr2 chr2 (3 Replies)
Discussion started by: Homa
3 Replies

8. Shell Programming and Scripting

Help with Sorting numbers in a file

Hi Guys, Would appreciate some help on sorting numbers on a file using the sort command. I have tried this and it's not sorting properly. what am i missing? cat testing_sort 1:21 4:18 2:17 7:14 9:19 3:12 0:16 8:13 5:20 6:15 10:11 sort -t: -nk1,1 -nk2,2 testing_sort (4 Replies)
Discussion started by: Apollo
4 Replies

9. OS X (Apple)

Sorting scientific numbers with sort

Hey everybody, I'm trying to sort scientific numbers in a descending order using the command sort -gr <file>. It works fine on a Linux-Server, but doesn't on my macbook pro with OS X 10.10.3 (Yosemite). I tried to sort the following: 6.38e-10 6.38e-10 1.80e-11 1.00e-10 1.48e-12 And... (9 Replies)
Discussion started by: plebs
9 Replies

10. UNIX for Beginners Questions & Answers

Convert ascii character values to number that comes between the numbers in UNIX

I have variable that contains multiple values of number and also include overpunch(i.e. # $ % etc) character so we want to replace it with numbers. here are the example: Code: 11500#.0# 28575$.5$ 527#.7# 42".2" 2794 .4 2279!.9! 1067&.7& 926#.6# 2279!.9! 885".5" 11714$.4$ 27361'.1'... (1 Reply)
Discussion started by: nadeemrafikhan
1 Replies
YAZ_SORT(3)								 1							       YAZ_SORT(3)

yaz_sort - Sets sorting criteria

SYNOPSIS
void yaz_sort (resource $id, string $criteria) DESCRIPTION
This function sets sorting criteria and enables Z39.50 Sort. Call this function beforeyaz_search(3). Using this function alone does not have any effect. When used in conjunction with yaz_search(3), a Z39.50 Sort will be sent after a search response has been received and before any records are retrieved with Z39.50 Present (yaz_present(3). PARAMETERS
o $id - The connection resource returned by yaz_connect(3). o $criteria - A string that takes the form field1 flags1 field2 flags2 where field1 specifies the primary attributes for sort, field2 seconds, etc.. The field specifies either a numerical attribute combinations consisting of type=value pairs separated by comma (e.g. 1=4,2=1) ; or the field may specify a plain string criteria (e.g. title. The flags is a sequence of the following characters which may not be separated by any white space. Sort Flags o a - Sort ascending o d - Sort descending o i - Case insensitive sorting o s - Case sensitive sorting RETURN VALUES
No value is returned. EXAMPLES
Example #1 Sort Criterias To sort on Bib1 attribute title, case insensitive, and ascending you would use the following sort criteria: 1=4 ia If the secondary sorting criteria should be author, case sensitive and ascending you would use: 1=4 ia 1=1003 sa PHP Documentation Group YAZ_SORT(3)
All times are GMT -4. The time now is 08:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy