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
MAPHIMBU(1)							   User Commands						       MAPHIMBU(1)

NAME
maphimbu - histogram builder for 1-d numerical and text data SYNOPSIS
maphimbu [OPTION]... [FILE] DESCRIPTION
This program produces 1-d histograms from numerical or text data input. It can be also used to estimate the probability distribution func- tion of a numerical variable - see http://en.wikipedia.org/wiki/Probability_density_function. OPTIONS
-x <int> x-data column (default is 1) -y <int> y-data column (default is 2); It is considered only when combined with '-m' or '-S' -d <float|int> delta size (dx-resolution) in case of numerical data; Keep in mind that 2 is not the same as 2.0: in the first case the numbers are treated as integers, in the latter as floats. -n normalize the result A) non-numerical data: n(x) = counts(x)/sum_of_counts B) numerical data: the normalized probability density func. is P(-INF < x <INF) = Int_[-INF:INF] P(x)*dx = 1 ; For the numerical integration an open x-data interval is assumed. -N normalize data against the total sum of counts (same as option '-n' with case A forced) -U normalize the result with x-range mapped to unit; The x-values are mapped to the interval [0:1], respectively Int_[0:1] P(x)*dx = 1; This option is mutually exclusive with '-n'. -S compute sums and normalized sums of y-values; The total sum of all y-values is used for the normalization. -m compute the arithmetic mean of y-values in the respective x-bar -s <int> sort output using the specified column; Header is skipped in this case. -g <int> sort output numerically using the specified column; Header is skipped in this case. -r do reverse sorting (in combination with '-g' and '-s') -C center histogram bars (shifts x-axis by 0.5*dx) -X treat hole line as one string (single data record) -H print a data description header -V print program version and exit --version output version and copyright information --help display help -h display short help (options summary) Note: this program is not intended for use in high order numerical computations. REPORTING BUGS
Report bugs to <gnu@mirendom.net> COPYRIGHT
Copyright (C) 2003-2007, 2009, 2011 Dimitar Ivanov License: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. maphimbu 2.8.4 February 2012 MAPHIMBU(1)
All times are GMT -4. The time now is 04:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy