Sort by second column numeric values


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Sort by second column numeric values
# 8  
Old 11-16-2015
You're not supplying the comma separator to sort. May I guess your locale allows for the comma being part of a number which would explain the difference between -n and -g options:
Quote:
-g, --general-numeric-sort
compare according to general numerical value
.
.
.
-n, --numeric-sort
compare according to string numerical value
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a numeric values in a certain column

Hi All, I am trying to replace a certain value from one place in a file . In the below file at position 35 I will have 8 I need to modify all 8 in that position to 7 I tried awk '{gsub("8","7",$35)}1' infile > outfile ----> not working sed -i 's/8/7'g' infile --- it is replacing all... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. Shell Programming and Scripting

Splitting the numeric vs alpha values in a column to distinct columns

How could i take an input file and split the numeric values from the alpha values (123 vs abc) to distinc columns, and if the source is blank to keep it blank (null) in both of the new columns: So if the source file had a column like: Value: |1 | |2.3| | | |No| I would... (7 Replies)
Discussion started by: driftlogic
7 Replies

3. 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

4. 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

5. 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

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

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

8. Shell Programming and Scripting

How to sort values inside one column?

Hi, Could someone please help me with this? I have a text file that has fields seperated by comma. The last column in it has multiple values seperated by "|". I need to sort values in the last column seperated by pipe..is there any way I can do this through script? Sample text file - ... (7 Replies)
Discussion started by: sncoupons
7 Replies

9. 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

10. 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
Login or Register to Ask a Question
Versions(3pm)						User Contributed Perl Documentation					     Versions(3pm)

NAME
Sort::Versions - a perl 5 module for sorting of revision-like numbers SYNOPSIS
use Sort::Versions; @l = sort { versioncmp($a, $b) } qw( 1.2 1.2.0 1.2a.0 1.2.a 1.a 02.a ); ... use Sort::Versions; print 'lower' if versioncmp('1.2', '1.2a') == -1; ... use Sort::Versions; %h = (1 => 'd', 2 => 'c', 3 => 'b', 4 => 'a'); @h = sort { versioncmp($h{$a}, $h{$b}) } keys %h; DESCRIPTION
Sort::Versions allows easy sorting of mixed non-numeric and numeric strings, like the 'version numbers' that many shared library systems and revision control packages use. This is quite useful if you are trying to deal with shared libraries. It can also be applied to applications that intersperse variable-width numeric fields within text. Other applications can undoubtedly be found. For an explanation of the algorithm, it's simplest to look at these examples: 1.1 < 1.2 1.1a < 1.2 1.1 < 1.1.1 1.1 < 1.1a 1.1.a < 1.1a 1 < a a < b 1 < 2 1.1-3 < 1.1-4 1.1-5 < 1.1.6 More precisely (but less comprehensibly), the two strings are treated as subunits delimited by periods or hyphens. Each subunit can contain any number of groups of digits or non-digits. If digit groups are being compared on both sides, a numeric comparison is used, otherwise a ASCII ordering is used. A group or subgroup with more units will win if all comparisons are equal. A period binds digit groups together more tightly than a hyphen. Some packages use a different style of version numbering: a simple real number written as a decimal. Sort::Versions has limited support for this style: when comparing two subunits which are both digit groups, if either subunit has a leading zero, then both are treated like digits after a decimal point. So for example: 0002 < 1 1.06 < 1.5 This won't always work, because there won't always be a leading zero in real-number style version numbers. There is no way for Sort::Versions to know which style was intended. But a lot of the time it will do the right thing. If you are making up version numbers, the style with (possibly) more than one dot is the style to use. USAGE
The function "versioncmp()" takes two arguments and compares them like "cmp". With perl 5.6 or later, you can also use this function directly in sorting: @l = sort versioncmp qw(1.1 1.2 1.0.3); The function "versions()" can be used directly as a sort function even on perl 5.005 and earlier, but its use is deprecated. AUTHOR
Ed Avis <ed@membled.com> and Matt Johnson <mwj99@doc.ic.ac.uk> for recent releases; the original author is Kenneth J. Albanowski <kjahds@kjahds.com>. Thanks to Hack Kampbjorn and Slaven Rezic for patches and bug reports. Copyright (c) 1996, Kenneth J. Albanowski. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2003-08-24 Versions(3pm)