Sponsored Content
Top Forums Shell Programming and Scripting Sort alpha on 1st field, numerical on 2nd field (sci notation) Post 302324978 by radoulov on Friday 12th of June 2009 10:45:19 AM
Old 06-12-2009
Code:
perl -e'
    print sort {
             ( split /\|\|\|/, $a )[0] cmp( split /\|\|\|/, $b )[0]
          || ( split /\|\|\|/, $b )[1] <=> ( split /\|\|\|/, $a )[1]
    } <>;
    ' infile


Last edited by radoulov; 06-12-2009 at 02:03 PM..
 

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
CSSORT(1p)						User Contributed Perl Documentation						CSSORT(1p)

NAME
cssort -- Czech sort FORMAT
cssort [ "-c"list | "-f"list ["-d"regexp]] [files ...] SYNOPSIS
cssort -c10-15,50-,25-45 < file cssort -f3,5-6 < file cssort -f3,5-6 -s: < file DESCRIPTION
Cssort is a utility that sorts input lines according to rules used in the Czech language. You can run it without any options, then it just uses whole lines for sorting. With the options, it's possible to specify parts of the lines to be used for comparison. list A comma-separated list of integer field numbers or field ranges. The are indexed from 1 and if a range is open (eg. "5-"), it means all remaining fields from the starting number. -c Stands for columns and the list that follows specifies byte ranges on the line. You will probably use this option to sort data with fixed width fields. -f Fields that will be used for sort. -d Delimiter that separates fields in the -f option. It is a Perl regular expression, the default is "[ ]+", which means any number of spaces or tabs in a row. The program assumes ISO-8859-2 encoding. Some way to specify another input encoding will come in the next versions. If you need to sort files with different encodings, you might want to check the cstocs conversion utility. SEE ALSO
Cz::Sort(3), cstocs(1). AUTHOR
Jan Pazdziora, adelton@fi.muni.cz. perl v5.10.1 2010-01-16 CSSORT(1p)
All times are GMT -4. The time now is 03:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy