trying to make an AWK code for ordering numbers in a column from least to highest


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trying to make an AWK code for ordering numbers in a column from least to highest
# 1  
Old 09-15-2009
Data trying to make an AWK code for ordering numbers in a column from least to highest

Hi all,

I have a large column of numbers like
Code:
5.6789
2.4578
9.4678
13.5673
1.6589
.....

I am trying to make an awk code so that awk can easily go through the column and arrange the numbers from least to highest like
Code:
1.6589
2.4578
5.6789

.......
can anybody suggest, how can I do thisSmilie

Last edited by vgersh99; 09-15-2009 at 11:25 AM.. Reason: code tags, PLEASE!
# 2  
Old 09-15-2009
you can get ur output in sort command itself.

sorn -n <filename>

please find the example:

Code:
$more a1
5.6789
2.4578
9.4678
13.5673
1.6589
2.8888
2.7593
124.234
3.3333
5.8990
99.234234
100.23432
2343
15799.00

Code:
$sort -n a1
1.6589
2.4578
2.7593
2.8888
3.3333
5.6789
5.8990
9.4678
13.5673
99.234234
100.23432
124.234
2343
15799.00
$


Last edited by vgersh99; 09-15-2009 at 11:25 AM.. Reason: code tags, PLEASE!
# 3  
Old 09-15-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 4  
Old 09-15-2009
hi thanks a lot for that....actually what i want to do is......i have a file with four columns like
Code:
1 2 4 5.6789
3 1 5 2.4578
1 3 2 9.4678
2 4 1 13.5673

So I want to order all the lines but on the basis of ordering the fourth column from least to highest value. something like this:-
Code:
3 1 5 2.4578
1 2 4 5.6789
1 3 2 9.4678
2 4 1 13.5673

thanks for your comments

Last edited by vgersh99; 09-15-2009 at 11:42 AM.. Reason: code tags, PLEASE!
# 5  
Old 09-15-2009
Simply
Code:
sort -k4rn file

# 6  
Old 09-15-2009
thanks ripat
sort -k4n file worked for me....i just removed the "r"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk script to get missing numbers in column 1

Hello to all, I have show below a file separated by commas. In first column has numbers where the last number is 13. 1,4 2,6 3,7 5,2 6,5 7,5 8,65 9,10 11,78 13,2 What I want to know is which numbers are missing from 1 to 13 (in this case 13 is last number in column 1). My real... (17 Replies)
Discussion started by: Ophiuchus
17 Replies

2. UNIX for Dummies Questions & Answers

Awk, highest and lowest value of a column

Hi again! I am still impressed how fast I get a solution for my topic "average specific column value awk" yesterday. The associative arrays in awk work fine for me! But now I have another question for the same project. Now I have a list like this 1 -0.1 1 0 1 0.1 2 0 2 0.2 2 -0.2 How... (10 Replies)
Discussion started by: bjoern456
10 Replies

3. Shell Programming and Scripting

Find lines with matching column 1 value, retain only the one with highest value in column 2

I have a file like: I would like to find lines lines with duplicate values in column 1, and retain only one based on two conditions: 1) keep line with highest value in column 3, 2) if column 3 values are equal, retain the line with the highest value in column 4. Desired output: I was able to... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

4. Shell Programming and Scripting

AWK "make a new column that include increasing numbers"

please help!!!!!! I have a file .txt that has only one column like that: 34.1 35.5 35.6 45.6 ... Now, i want to add a column in the left in which the values of this column increase by 0.4 , for example: 0.0 34.1 0.4 35.5 0.8 35.6 1.2 45.6 How can i do with awk instructions??? ... (2 Replies)
Discussion started by: tienete
2 Replies

5. Shell Programming and Scripting

using AWK to make four column to one column

Gurus, I have file contain following line. ,0113955056,,XAgent-Suspend ,0119418233,,XAgent-Suspend ,0102119078,,XAgent-Suspend I want to make it one column file. How to do this using awk? Can anyone help with 'awk' 0113955056 0119418233 0102119078 (5 Replies)
Discussion started by: thepurple
5 Replies

6. Shell Programming and Scripting

Calculate data and make it into new column using awk

Hi everyone, just some simple question... i've been using a awk script to calculate my data... i have 3 files: file a1.txt: 2 3 4 5 3 4 file a2.txt: 4 5 6 7 8 (1 Reply)
Discussion started by: yat
1 Replies

7. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

8. Shell Programming and Scripting

Appending lines with word frequencies, ordering and indexing a column

Dear All, I have the following input data: w1 20 g1 w1 10 g1 w2 12 g1 w2 23 g1 w3 10 g1 w3 17 g1 w3 12.5 g1 w3 21 g1 w4 11 g1 w4 13.2 g1 w4 23 g1 w4 18 g1 First I seek to find the word frequencies in col1 and sort col2 in ascending order for each change in a col1 word. Second,... (5 Replies)
Discussion started by: Ghetz
5 Replies

9. Shell Programming and Scripting

AWK processing -numbers to another column

Hi Guys, I'm trying to clean up my home logger file and can't seem to work this out. Here is my data: 10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 -49.1 220.9 10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9 10-19-2009 08:41 00.1 00.0 00.7 00.8 24.5 0.0... (2 Replies)
Discussion started by: BeJay
2 Replies

10. Shell Programming and Scripting

Perl ? - How to find and print the lowest and highest numbers punched in by the user?

. . . . . . (3 Replies)
Discussion started by: some124one
3 Replies
Login or Register to Ask a Question