Sponsored Content
Top Forums Shell Programming and Scripting Sort alpha on 1st field, numerical on 2nd field (sci notation) Post 302324976 by FrancoisCN on Friday 12th of June 2009 10:37:55 AM
Old 06-12-2009
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 therefore smaller than 3. The output I want would be

abc ||| 3 ||| ble
abc ||| 5e-05 ||| bla
def ||| 1 ||| abc
def ||| 0.2 ||| def
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sort columns by field

hello, i have a table contain many columns delimited by blank. i want to sort this table by the 2 columns and 3 one and i want to keep the first line inchanged? how can i do using the sort command? thanks table like : field1 field2 field3 field4 x y z b t h r n .. (4 Replies)
Discussion started by: kamel.seg
4 Replies

2. Shell Programming and Scripting

get a name according to the 2nd field

Hi, I have a file with this format: name number -------------- ----------- AAA 11700 BBB 6000 CCC 6000 I want to catch any of these names if number > 200 How to do that? at a... (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

3. UNIX for Advanced & Expert Users

Sort on basis of particular field

05.50.25:AIRE.S:RESTRICTED:S2: 05.50.25:ANDR.VI:RESTRICTED:S2: 05.50.25:BASF.MI:RESTRICTED:N: 05.50.25:BMWG.DE:RESTRICTED:N: 05.50.25:BORE.ST:RESTRICTED:N: I can sort of the basis of second field using " sort -t: -k2,2 " but what i want to sort the data is on the basis its extension e.g.:... (9 Replies)
Discussion started by: manishma71
9 Replies

4. Shell Programming and Scripting

Appending 1st field in a file into 2nd field in another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (0 Replies)
Discussion started by: amurib
0 Replies

5. Shell Programming and Scripting

Append 1st field from a file into 2nd field of another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (1 Reply)
Discussion started by: amurib
1 Replies

6. Shell Programming and Scripting

Sort help on non numeric field

Hi, I am unable to sort data on the first field $cat t Jim,212121,Seattle Bill,404404,Seattle Steve,246810,Nevada Scott,212277,LosAngeles Jim,212121,Ohio sort -t"," -k1,2 t Bill,404404,Seattle Jim,212121,Ohio Jim,212121,Seattle Scott,212277,LosAngeles Steve,246810,Nevada (7 Replies)
Discussion started by: Shivdatta
7 Replies

7. Shell Programming and Scripting

how to find the 2nd field

java....4059... compsite 62u IPv4 170747 TCP *:9400 (LISTEN) java...... 05... compsite 109u IPv4 171216 TCP *:9401 (LISTEN) This is Joust formated like this Please Repace "." with space" " All are Right Justfied Output :- 4058 and 05 so that i can kill this (1 Reply)
Discussion started by: pareshpatra
1 Replies

8. Shell Programming and Scripting

Sort field and uniq

I have a flatfile A.txt 2012/12/04 14:06:07 |trees|Boards 2, 3|denver|mekong|mekong12 2012/12/04 17:07:22 |trees|Boards 2, 3|denver|mekong|mekong12 2012/12/04 17:13:27 |trees|Boards 2, 3|denver|mekong|mekong12 2012/12/04 14:07:39 |rain|Boards 1|tampa|merced|merced11 How do i sort and get... (3 Replies)
Discussion started by: sabercats
3 Replies

9. UNIX for Dummies Questions & Answers

Combine Similar Output from the 2nd field w.r.t 1st Field

Hi, For example: I have: HostA,XYZ HostB,XYZ HostC,ABC I would like the output to be: HostA,HostB: XYZ HostC:ABC How can I achieve this? So far what I though of is: (1 Reply)
Discussion started by: alvinoo
1 Replies
SORT(1) 						      General Commands Manual							   SORT(1)

NAME
sort - sort and/or merge files SYNOPSIS
sort [ -cmuMbdfinrwtx ] [ +pos1 [ -pos2 ] ... ] ... [ -k pos1 [ ,pos2 ] ] ... [ -o output ] [ -T dir ... ] [ option ... ] [ file ... ] DESCRIPTION
Sort sorts lines of all the files together and writes the result on the standard output. If no input files are named, the standard input is sorted. The default sort key is an entire line. Default ordering is lexicographic by runes. The ordering is affected globally by the following options, one or more of which may appear. -M Compare as months. The first three non-white space characters of the field are folded to upper case and compared so that precedes etc. Invalid fields compare low to -b Ignore leading white space (spaces and tabs) in field comparisons. -d `Phone directory' order: only letters, accented letters, digits and white space are significant in comparisons. -f Fold lower case letters onto upper case. Accented characters are folded to their non-accented upper case form. -i Ignore characters outside the ASCII range 040-0176 in non-numeric comparisons. -w Like -i, but ignore only tabs and spaces. -n An initial numeric string, consisting of optional white space, optional plus or minus sign, and zero or more digits with optional decimal point, is sorted by arithmetic value. -g Numbers, like -n but with optional e-style exponents, are sorted by value. -r Reverse the sense of comparisons. -tx `Tab character' separating fields is x. The notation +pos1 -pos2 restricts a sort key to a field beginning at pos1 and ending just before pos2. Pos1 and pos2 each have the form m.n, optionally followed by one or more of the flags Mbdfginr, where m tells a number of fields to skip from the beginning of the line and n tells a number of characters to skip further. If any flags are present they override all the global ordering options for this key. A missing .n means .0; a missing -pos2 means the end of the line. Under the -tx option, fields are strings separated by x; otherwise fields are non-empty strings separated by white space. White space before a field is part of the field, except under option -b. A b flag may be attached independently to pos1 and pos2. The notation -k pos1[,pos2] is how POSIX sort defines fields: pos1 and pos2 have the same format but different meanings. The value of m is origin 1 instead of origin 0 and a missing .n in pos2 is the end of the field. When there are multiple sort keys, later keys are compared only after all earlier keys compare equal. Lines that otherwise compare equal are ordered with all bytes significant. These option arguments are also understood: -c Check that the single input file is sorted according to the ordering rules; give no output unless the file is out of sort. -m Merge; assume the input files are already sorted. -u Suppress all but one in each set of equal lines. Ignored bytes and bytes outside keys do not participate in this comparison. -o The next argument is the name of an output file to use instead of the standard output. This file may be the same as one of the inputs. -Tdir Put temporary files in dir rather than in /tmp. EXAMPLES
Print in alphabetical order all the unique spellings in a list of words where capitalized words differ from uncapitalized. Print the users file sorted by user name (the second colon-separated field). Print the first instance of each month in an already sorted file. Options -um with just one input file make the choice of a unique representative from a set of equal lines predictable. grep -n '^' input | sort -t: +1f +0n | sed 's/[0-9]*://' A stable sort: input lines that compare equal will come out in their original order. FILES
/tmp/sort.<pid>.<ordinal> SOURCE
/sys/src/cmd/sort.c SEE ALSO
uniq(1), look(1) DIAGNOSTICS
Sort comments and exits with non-null status for various trouble conditions and for disorder discovered under option -c. BUGS
An external null character can be confused with an internally generated end-of-field character. The result can make a sub-field not sort less than a longer field. Some of the options, e.g. -i and -M, are hopelessly provincial. SORT(1)
All times are GMT -4. The time now is 03:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy