Help with sort word followed by exponential number and numeric number at the same time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with sort word followed by exponential number and numeric number at the same time
# 1  
Old 03-27-2013
Help with sort word followed by exponential number and numeric number at the same time

Input file:
[code]
ID_34 2E-69 2324
ID_1 0E0 3254
ID_1 0E0 5434
ID_5 0E0 436
ID_1 1E-14 2524
ID_1 5E-52 46437
ID_3 65E-20 45467
ID_1 0E0 6578
...
[code]
Desired output file:
Code:
ID_1 0E0 6578
ID_1 0E0 5434
ID_1 0E0 3254
ID_1 5E-52 46437
ID_1 1E-14 2524
ID_3 65E-20 45467
ID_5 0E0 436
ID_34 2E-69 2324
...

I wanna to sort the first column from smallest to largest first. After then, sort the exponential number from smallest to largest. At last, only sort the third column from largest to smallest.
All must sort at the same time running.

command I try:
Code:
sort -t_ -k2n -k2,2g -k3,3r input_file

But it seems like can't really work if I deal with huge data set.
Thanks for any advice.
# 2  
Old 03-27-2013
Code:
$ sort -t' ' -k1.4n file
ID_1 0E0 3254
ID_1 0E0 5434
ID_1 0E0 6578
ID_1 1E-14 2524
ID_1 5E-52 46437
ID_3 65E-20 45467
ID_5 0E0 436
ID_34 2E-69 2324

# 3  
Old 03-27-2013
Hi anbu23,

I hope that second column is from smallest to largest while third column is largest to smallest.

Thanks ya Smilie
# 4  
Old 03-27-2013
Combining both your proposals should do the job:
Code:
$ sort  -k1.4n -k2,2g -k3,3r file
ID_1 0E0 6578
ID_1 0E0 5434
ID_1 0E0 3254
ID_1 5E-52 46437
ID_1 1E-14 2524
ID_3 65E-20 45467
ID_5 0E0 436
ID_34 2E-69 2324

This User Gave Thanks to RudiC For This Post:
# 5  
Old 03-27-2013
Thanks RudiC.
It worked based on the input file.
Do you mind to explain what is the meaning of "sort -k1.4n" ?
I can't really understand it.

Thanks first Smilie
# 6  
Old 03-27-2013
man sort:
Quote:
-k, --key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of line). See POS syntax below
.
.
.
POS is F[.C][OPTS], where F is the field number and C the character position in the field; both are origin 1. If neither -t nor -b
is in effect, characters in a field are counted from the beginning of the preceding whitespace. OPTS is one or more single-letter
ordering options, which override global ordering options for that key. If no key is given, use the entire line as the key.
so it sorts using field 1 char 4 numerical as the first sort key. To be very precise, and avoid side effects, you would need to modify it to k1.4,1n
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies

2. UNIX for Dummies Questions & Answers

Sort by alpha then by number

I have a file like the following: /vol/release /vol/listing /vol/trees7 /vol/toperforce /vol/trees10 /vol/trees2 /vol/wtrain I have tried the following: cat file | sort -t/ -dfk3.1 -t/ -k3.6n That did not work. What I want to do is have the file sorted so that the first... (2 Replies)
Discussion started by: newbie2010
2 Replies

3. Shell Programming and Scripting

Print only word not number

Hi, Need to extract only words not numbers #cat test.txt 123456 oracle web 56789 s21adm Required output #grep <options> test.txt oracle web s21adm Note, in between integer "s21adm" is required but not with full integer "123456" and "56789" (6 Replies)
Discussion started by: ksgnathan
6 Replies

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

5. Shell Programming and Scripting

How to sort the files according to the number?

Hi Everyone, I have a question: I have a lot of file named like or10000.dat, or9100.dat, or100.dat, or3100.dat... I want to deal with these files according to the number in the name. So I want to deal with or100.dat first and then or3100.dat and so on. I used : for i in `ls or*.dat |... (11 Replies)
Discussion started by: wxuyec
11 Replies

6. Shell Programming and Scripting

How can I sort by n number is like words?

I want to sort a file with a list of words, in order of most occuring words to least occurring words as well as alphabetically. ex: file1: cat 3 cat 7 cat 1 dog 3 dog 5 dog 9 dog 1 ape 4 ape 2 I want the outcome to be: file1.sorted: dog 1 (12 Replies)
Discussion started by: castrojc
12 Replies

7. UNIX for Advanced & Expert Users

query display number lines or records present in file only numeric value -without filename

Hi all Thanks in advance........... Please help me for this issue............ I have a file it has 11 records . I used the command like .... >$ wc -l file 11 file I'm getting output like 11 file (no.of records along with filename) here my requirement is, I want to display only... (3 Replies)
Discussion started by: ksrivani
3 Replies

8. Linux

How to sort the number of occurrences

file:///C:/Users/TSHEPI%7E1.LEB/AppData/Local/Temp/moz-screenshot.pngATM@ubuntu:~$ cat numbers2 | sort -n | uniq -c 1 7 1 11 2 10 3 the 1st numbers are the counts from the command "uniq -c", which represent the number of occurrences of each in the file. The "sort -n"... (4 Replies)
Discussion started by: lebogot
4 Replies

9. Shell Programming and Scripting

Conversion of Exponential to numeric in awk- not correct output

Hi All, I have 1 million records file. Using awk, I am counting the number of records. But as the number is huge, after crossing a number, awk is displaying it in exponential format. At the end, I need to verify this count given by awk with expected count. But as it is in exponential format,... (3 Replies)
Discussion started by: ssunda6
3 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