Sort - original order .... Help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sort - original order .... Help
# 1  
Old 06-01-2005
Sort - original order .... Help

Hi all,
I want to sort a file based on the number in the 9th column
I've tried both of the following commands
sort -k 9,9n file_to_sort.dat

sort +8 -n file_to_sort.dat

both resulting in the same output which does sort col 9 nummerically
but it doesn't output the lines in the original order they occurred

for example if I input
10.000000 2 21 13 0.7 0.9 -0.1 0.3 0 -0.098
10.389985 2 43 21 0.3 0.7 0.3 0.3 0 0.310
11.473330 2 29 21 0.5 0.7 0.1 0.3 0 0.126
11.978573 2 30 21 0.4 0.6 0.1 0.3 0 0.151
26.455198 2 12 23 0.4 0.6 0.4 0.4 1 0.151
101.045498 2 21 36 0.8 0.5 -0.1 0.1 0 -0.098
102.346752 2 34 54 0.3 0.4 0.9 0.6 1 0.275
109.565385 2 21 33 0.7 0.5 0.1 0.1 0 -0.098
110.237589 2 32 23 0.9 0.6 0.8 0.6 1 0.252
111.59287 2 32 23 0.9 0.2 0.9 0.7 1 0.252
126.697432 2 22 32 0.7 0.5 0.1 0.1 0 -0.098

results in
10.000000 2 21 13 0.7 0.9 -0.1 0.3 0 -0.098
101.045498 2 21 36 0.8 0.5 -0.1 0.1 0 -0.098
10.389985 2 43 21 0.3 0.7 0.3 0.3 0 0.310
109.565385 2 21 33 0.7 0.5 0.1 0.1 0 -0.098
11.473330 2 29 21 0.5 0.7 0.1 0.3 0 0.126
11.978573 2 30 21 0.4 0.6 0.1 0.3 0 0.151
126.697432 2 22 32 0.7 0.5 0.1 0.1 0 -0.098
etc

whereas I expect it to look like the original file
with numbers in col 1 in their orginal order except the lines that have col 9=1 which should be moved towards the end and in their original order also
10.000000 2 21 13 0.7 0.9 -0.1 0.3 0 -0.098
10.389985 2 43 21 0.3 0.7 0.3 0.3 0 0.310
11.473330 2 29 21 0.5 0.7 0.1 0.3 0 0.126
11.978573 2 30 21 0.4 0.6 0.1 0.3 0 0.151
101.045498 2 21 36 0.8 0.5 -0.1 0.1 0 -0.098
109.565385 2 21 33 0.7 0.5 0.1 0.1 0 -0.098
126.697432 2 22 32 0.7 0.5 0.1 0.1 0 -0.098
...
26.455198 2 12 23 0.4 0.6 0.4 0.4 1 0.151
102.346752 2 34 54 0.3 0.4 0.9 0.6 1 0.275
110.237589 2 32 23 0.9 0.6 0.8 0.6 1 0.252
111.59287 2 32 23 0.9 0.2 0.9 0.7 1 0.252

Thanks a mil to anyone who can offer any suggestions

Best Regards,
Olga
# 2  
Old 06-01-2005
Code:
sort -k9,9n -k1,1n inputfile

-or-
Code:
sort -n +8 +0 inputfile

Cheers
ZB
# 3  
Old 06-01-2005
Thanks

Works perfect - Excellent

Thanks a million,
Olga
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sort in chronological order

I am trying to sort a log file in chronological order to identify which ones did not process and still have an old (probably yesterday's) date. This is a sample of the file:flatf 010140 flatf Thu May 10 22:22:11 CST 2018 flats finished flatf 010142 flatf Thu May 10 22:31:25 CST 2018 flats... (4 Replies)
Discussion started by: wbport
4 Replies

2. Shell Programming and Scripting

Sort by specific order?

Hello all I was wondering if someone has an idea how to sort by a specific order, let's say by a specific alphabet containing only 4 letters like (d,s,a,p) instead of (a,b,c....z) ?? Cheers! (6 Replies)
Discussion started by: cabrao
6 Replies

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

4. UNIX for Dummies Questions & Answers

sort by column or specific order

Hi, I need to sort it by column or need it in a specific order... input is ===== uid=shashi country= india region =0 ph=0 uid= jon region= asia ph= 12345 country=0 uid = man country= india ph=2222 region=0 uid= neera region= asia ph= 125 country=0 output should be uid=shashi ... (1 Reply)
Discussion started by: hegdeshashi
1 Replies

5. Shell Programming and Scripting

sort order HP UX / SUN Solaris

Hi! simple 'sort' produces a different output on SUN OS than on HP. Lines with empty fields inside the key are sorted at the beginning on SUN; on HP they are at the end. i.e SUN 03|ref|168126310|702578641|||||||||||||| 03|ref|168126310|702578641|DEL| 03|ref|168126310|702578641|FW|... (5 Replies)
Discussion started by: strolchFX
5 Replies

6. UNIX for Dummies Questions & Answers

sort -reverse order

I need to sort the particular column only in reverse order how i can give it.. if i give the -r option the whole file is getting sorted in reverse order. 1st 2nd col 3rd C col 4th col 5th col ------------------------------------------- C... (7 Replies)
Discussion started by: sivakumar.rj
7 Replies

7. Shell Programming and Scripting

SORT order in Unix

I am converting mainframes JCL to be used in shell on a one to one basis... when i use the sort command unix does ascii sort as a result which numbers are first followed by charecters in the Ascending sort ... but themainframes uses the EBCDIC as result gives the charecters followed by numbers in... (5 Replies)
Discussion started by: bourne
5 Replies

8. Shell Programming and Scripting

sort a file in reverse order

I a file with log entries... I want to sort it so that the last line in the file is first and the first line is last.. eg. Sample file 1 h a f 8 6 After sort should look like 6 8 f a h 1 (11 Replies)
Discussion started by: frustrated1
11 Replies

9. UNIX for Dummies Questions & Answers

Sort / ascending order

What's the command to sort a file in ascending order and redirect the output to another file? Thanks!!!!!! (1 Reply)
Discussion started by: gyik
1 Replies
Login or Register to Ask a Question