Sponsored Content
Top Forums Shell Programming and Scripting Sort help on non numeric field Post 302531855 by Scott on Saturday 18th of June 2011 08:34:50 AM
Old 06-18-2011
Maybe you need a "stable" sort:

Code:
$ sort -s -t"," -k1,2 t
Bill,404404,Seattle
Jim,212121,Seattle
Jim,212121,Ohio
Scott,212277,LosAngeles
Steve,246810,Nevada

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to numeric sort on field time

i want to sort time field given by who command as a whole i have tried like this who|sort -n +4 -5 (1 Reply)
Discussion started by: rahulspatil_111
1 Replies

2. Shell Programming and Scripting

Numeric sort error

Hello all I have data like below where the column with values (PRI, SEC ) is the char field and the rest are Numeric Fields. 200707,9580,58,7,2,1,PRI,1,1,137,205594,0,5,10,-45.51,-45.51 200707,9580,58,7,2,1,SEC,1,1,137,205594,0,5,10,-45.51,45.51... (1 Reply)
Discussion started by: vasuarjula
1 Replies

3. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

4. Linux

Using sort command to get numeric ascending order

HI everyone, I am trying to use the unix sort command to get a list of numbers sorted in ascending order but having trouble in getting it to work. An example of this issue would be when i am trying to sort the following three number each on a different line "1" , "2" and "116" the sort command... (3 Replies)
Discussion started by: wali4813
3 Replies

5. Shell Programming and Scripting

Perl script to sort data on second numeric field

Hi, I'm a learner of PERL programming. I've a input file with the below data: SWAT_5, 1703, 2010-09-21 SWAT_6, 2345, 2010-09-21 SWAT_7, 1792, 2010-09-21 SWAT_8, 1662, 2010-09-21 SWAT_9, 1888, 2010-09-21 VXHARP_1, 171, 2010-09-21 I need to sort this data based on the second... (6 Replies)
Discussion started by: ganapati
6 Replies

6. UNIX for Dummies Questions & Answers

sort files by numeric filename

dear all, i have .dat files named as: 34.dat 2.dat 16.dat 107.dat i would like to sort them by their filenames as: 2.dat 16.dat 34.dat 107.dat i have tried numerous combinations of sort and ls command (in vain) to obtain : 107.dat 16.dat 2.dat 34.dat (1 Reply)
Discussion started by: chen.xiao.po
1 Replies

7. Shell Programming and Scripting

Sort numeric order

Hi I am using this cat substitutionFeats.txt | gawk '{$0=gensub(/\t/,"blabla",1);print}' | gawk '{print length, $0}' | sort -n | sort -r and the "sort -n" command doesn't work as expected: it leads to a wrong ordering: 64 Adjustable cuffs 64 Abrasion- 64 Abrasion pas 647 Sanitized 647... (4 Replies)
Discussion started by: louisJ
4 Replies

8. Shell Programming and Scripting

[Solved] sort on numeric part of field

I have ran into a heavy case of PEBCAK*) and could need some advice on what i do wrong: OS is Linux (kernel 2.6.35), sort --version reports "8.5" from 2010, shell is ksh. Originally i had a file with with the following structure: hdisk1 yyy hdisk2 yyy hdisk3 yyy hdisk4 yyy hdisk5 yyy... (2 Replies)
Discussion started by: bakunin
2 Replies

9. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

10. UNIX for Advanced & Expert Users

Sort by second column numeric values

From googling and reading man pages I figured out this sorts the first column by numeric values. sort -g -k 1,1 Why does the -n option not work? The man pages were a bit confusing. And what if I want to sort the second column numerically? I haven't been able to figure that out. The file... (7 Replies)
Discussion started by: cokedude
7 Replies
RADIXSORT(3)						   BSD Library Functions Manual 					      RADIXSORT(3)

NAME
radixsort, sradixsort -- radix sort LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <limits.h> #include <stdlib.h> int radixsort(const u_char **base, int nmemb, u_char *table, u_int endbyte); int sradixsort(const u_char **base, int nmemb, u_char *table, u_int endbyte); DESCRIPTION
The radixsort() and sradixsort() functions are implementations of radix sort. These functions sort an nmemb element array of pointers to byte strings, with the initial member of which is referenced by base. The byte strings may contain any values. End of strings is denoted by character which has same weight as user specified value endbyte. endbyte has to be between 0 and 255. Applications may specify a sort order by providing the table argument. If non-NULL, table must reference an array of UCHAR_MAX + 1 bytes which contains the sort weight of each possible byte value. The end-of-string byte must have a sort weight of 0 or 255 (for sorting in reverse order). More than one byte may have the same sort weight. The table argument is useful for applications which wish to sort differ- ent characters equally, for example, providing a table with the same weights for A-Z as for a-z will result in a case-insensitive sort. If table is NULL, the contents of the array are sorted in ascending order according to the ASCII order of the byte strings they reference and endbyte has a sorting weight of 0. The sradixsort() function is stable, that is, if two elements compare as equal, their order in the sorted array is unchanged. The sradixsort() function uses additional memory sufficient to hold nmemb pointers. The radixsort() function is not stable, but uses no additional memory. These functions are variants of most-significant-byte radix sorting; in particular, see D.E. Knuth's Algorithm R and section 5.2.5, exercise 10. They take linear time relative to the number of bytes in the strings. RETURN VALUES
Upon successful completion 0 is returned. Otherwise, -1 is returned and the global variable errno is set to indicate the error. ERRORS
[EINVAL] The value of the endbyte element of table is not 0 or 255. Additionally, the sradixsort() function may fail and set errno for any of the errors specified for the library routine malloc(3). SEE ALSO
sort(1), qsort(3) Knuth, D.E., "Sorting and Searching", The Art of Computer Programming, Vol. 3, pp. 170-178, 1968. Paige, R., "Three Partition Refinement Algorithms", SIAM J. Comput., No. 6, Vol. 16, 1987. McIlroy, P., "Computing Systems", Engineering Radix Sort, Vol. 6:1, pp. 5-27, 1993. HISTORY
The radixsort() function first appeared in 4.4BSD. BSD
January 27, 1994 BSD
All times are GMT -4. The time now is 09:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy