List number in decending order using AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List number in decending order using AWK
# 1  
Old 08-13-2008
List number in decending order using AWK

Hi All,

Can anyone show me how to list the below numbers in decending order?
I have a code to find out whats the largest number though but can it be modified to in-corporate in function ?
Thanks in advance

Input:

20
30
10
40
50

Output:

50
40
30
20
10

Code:
BEGIN{
F[1] = 20;
F[2] = 30;
F[3] = 10;
F[4] = 40;
F[5] = 50;
}
{
for (i=1 ; i<4 ; i++) {
        if (F[i] > HIGH_F) {HIGH_F = F[i]}

}
}
END{printf("Largest number is %s",HIGH_F) }

# 2  
Old 08-13-2008
The mawk manual page has an example isort implementation in awk.
# 3  
Old 08-13-2008
why not use 'sort'?

'sort -r inputfile'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to list files in ascending order?

Hi, I need to list files in ascending order. Filenames are in format inpTDT_1, inpTDT_2, inpTDT_3 and so on. I want to list them in the ascending order based on the digit after underscore and send the output to a file. Please help (5 Replies)
Discussion started by: Neelkanth
5 Replies

2. Shell Programming and Scripting

Number of elements, average value, min & max from a list of numbers using awk

Hi all, I have a list of numbers. I need an awk command to find out the numbers of elements (number of numbers, sort to speak), the average value the min and max value. Reading the list only once, with awk. Any ideas? Thanks! (5 Replies)
Discussion started by: black_fender
5 Replies

3. Shell Programming and Scripting

script for remove descending order number

hi all i want to remove some descending order number example : 1 100 200 135.00 Gk_wirs 1 1 100 200 136.00 Gk_wirs 50 1 110 210 138.00 Gk_wirs 60 1 100 200 136.00 Gk_wirs 57 ----> how to remove... (6 Replies)
Discussion started by: nithyanandan
6 Replies

4. Shell Programming and Scripting

[awk]compare a number in a string with a list

Hi, I have a program written in awk and I want to extend it to do another task. My program is a list of CVS log reports of a repository. For each file, I have some fields. One of the fields is the comment field. I want to know how I can check if a comment (which is a free text field)... (8 Replies)
Discussion started by: sandeepk1611
8 Replies

5. UNIX for Dummies Questions & Answers

how to list descending order

Hi, I want to short descending all the files according to their size.Please help me.. (1 Reply)
Discussion started by: jyotidas
1 Replies

6. Shell Programming and Scripting

Counts a number of unique word contained in the file and print them in alphabetical order

What should be the Shell script that counts a number of unique word contained in a file and print them in alphabetical order line by line? (7 Replies)
Discussion started by: proactiveaditya
7 Replies

7. Shell Programming and Scripting

Regarding about the print line number/order

Hello, I am trying to print line number/order using this command awk '{print $0, FNR}' myfilename 11006 A41 1888 11006 A41 1888 11006 A41 1888 11006 A41 ... (2 Replies)
Discussion started by: davidkhan
2 Replies

8. Shell Programming and Scripting

AWK: list with ordinal number

Could somebody solve this problem? I want to create a list from the last ten modificated files and the end of rows I would like to take an ordinal number in fix position. My solution: ls -lt | grep ´^-´ | sed 10q | awk ´{printf "%s\t%2i\n", %0, NR}´ But so the ordinal number isn't in a... (1 Reply)
Discussion started by: mig8
1 Replies

9. Shell Programming and Scripting

filter and get the latest order number

hello, how can I filter and get the latest order number (last five digits) below: input file: johnmm00001 maryyy00121 johnm100222 johnmm00003 maryyy00122 output file: johnmm00003 maryyy00122 johnm100222 (6 Replies)
Discussion started by: happyv
6 Replies

10. Shell Programming and Scripting

adding order number in the output file

Hello, I have a list of all order number like below: maryu01001 johnm00003 peter02234 catmy66751 For the above, all number must in 5 digits and I need to add one into the number and output a new list like below: maryu01002 johnm00004 peter02235 catmy66752 How can write a... (20 Replies)
Discussion started by: happyv
20 Replies
Login or Register to Ask a Question