Help with awk sorting with different values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk sorting with different values
# 1  
Old 01-14-2013
Help with awk sorting with different values

Hello,

I have a file as follows:

BTA Pos KLD

Code:
4    79.7011    5.7711028907

4     79.6231    5.7083918219

5    20.9112    4.5559494707

5    58.0002    3.4423546273

6    38.2569    4.7108176788

6    18.3889    7.3631759258

I want to sort the second column based on each values in the first column, that is forexample sorting for BTA 4, then for BTA 5, then for BTA 6 and so on to have this output:

Code:
4     79.6231    5.7083918219

4    79.7011    5.7711028907

5    20.9112    4.5559494707

5    58.0002    3.4423546273

6    18.3889    7.3631759258

6    38.2569    4.7108176788

Thank you in advance.
# 2  
Old 01-14-2013
Try:
Code:
sort -k1,2n file | awk NF ORS='\n\n'

The awk bit is used to remove and add the empty lines ..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting out unique values from output of for loop.

Hi , i have a belwo script which is used to get sectors per track value extarcted from Solaris machine: for DISK in /dev/dsk/c*t*d*s*; do value=`prtvtoc "$DISK" | sed -n -e '/Dimensions/,/Flags/{/Dimensions/d; /Flags/d; p; }' | sed -n -e '/sectors\/track/p'`; if ; then echo... (4 Replies)
Discussion started by: omkar.jadhav
4 Replies

2. UNIX for Dummies Questions & Answers

Sorting and saving values based on unique entries

Hi all, I wanted to save the values of a file that contains unique entries based on a specific column (column 4). my sample file looks like the following: input file: 200006-07file.txt 145 35 10 3 147 35 12 4 146 36 11 3 145 34 12 5 143 31 15 4 146 30 14 5 desired output files:... (5 Replies)
Discussion started by: ida1215
5 Replies

3. UNIX for Dummies Questions & Answers

Sorting columns for specific values

Dear All, i have a column with values in excel table: ATGC22327-p66 ATGC15922-p239 ATGC12710-p21743567 ATGC08037-p186 ATGC07969-p173 ATGC07345-p48534 ATGC02767-p254234 ATGC02124-p2177451 ATGC02124-p1459 ATGC01930-p3005 I need to... (6 Replies)
Discussion started by: AAWT
6 Replies

4. UNIX for Dummies Questions & Answers

Sorting a file in descending order when you have 10e- values

Hi, I am trying to sort the following file in descending order of its fourth column. 2 1 363828 -2.423225e-03 3 1 363828 4.132763e-03 3 2 363828 8.150133e-03 4 1 363828 4.126890e-03 I use sort -k4,4g -r input.txt > output.txt ... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

sorting left-justified numeric values

I have a file which looks roughly like this: 996 mmmmmmm 996 xxxxxxxxxxxxx 99600 ssssssssss 9964 fffffffffffff and would like to sort it numerically on the first field. I tried: sort -nr --key=1 .... The output I get is: 99600 ssssssssss 9964 ... (3 Replies)
Discussion started by: rovf
3 Replies

6. Shell Programming and Scripting

AWK Sorting with range values

Hello, I am looking for some help on GAWK script. I have a list of phone numbers as below. I need to sort these in the range of first 6 digits. 2402170338 2402170387 2402170478 2402170744 2403100025 2403100026 2403100027 2403100028 So for the above sample data, I require an output... (9 Replies)
Discussion started by: Diwakar9
9 Replies

7. Shell Programming and Scripting

Sorting values of hash in ascending order using Perl

I want to sort values of a hash in ascending order. my %records; for my $value (sort values %records){print $value,"\n";} When I use the above code I get values in this order: 1,10,11,2,3,4,5,6,7,8,9. But, I need values in my output in this order: 1,2,3,4,5,6,7,8,9,10,11. Can Someone... (1 Reply)
Discussion started by: koneru_18
1 Replies

8. Shell Programming and Scripting

Sorting positive and negative values

Hello, I have a list like this : 1 2 -4 0 -3 -7 5 6 etc. Is there a way to remove all the positive values and print only the negative values, without using grep, sed or awk? Thanks, Prasanna (4 Replies)
Discussion started by: prasanna1157
4 Replies

9. Shell Programming and Scripting

Sorting multi-column values from a specific file

Hi, all. I need a shell script which gathers data from a remote XML file and then displays it according to my needs.. I need this for my job due to the fact that I need to keep track price changes of euro, usd, gold, etc. The XML file I am talking about is located at this page: cnnturk dot... (4 Replies)
Discussion started by: canimsin
4 Replies

10. Shell Programming and Scripting

sorting null values

Hi I have a file with the values abc res set kls lmn ops i want to sort this file with the null values at the bottom of the file OUTPUT should look like this abc kls lmn ops (6 Replies)
Discussion started by: vickyhere
6 Replies
Login or Register to Ask a Question