Sponsored Content
Top Forums Shell Programming and Scripting Sort from highest to lowest number Post 302960710 by summer_cherry on Wednesday 18th of November 2015 09:32:32 PM
Old 11-18-2015
awk

Code:
awk 'BEGIN{
FS="[ \t]+"
}
{
        if(NR%4==1){
                user=$1
                users[user]=$0
                sort[NR]=$2" "user
        }
        else{
                users[user]=users[user]"\n"$0
        }
}
END{
        n=asort(sort)
        for(i=1;i<=n;i++){
                split(sort[i],items," ")
                user = items[2]
                print(users[user])
        }

}' a

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sort with highest wc

Hi :) I'm a unix beginner and i've recently got an assignment to write up a script to print the most common IP address that made requests from a webserver. I'm really lost in this one...and if someone could pls tell me where to start i'll be really greatful ! thanx (1 Reply)
Discussion started by: ymf
1 Replies

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

3. Shell Programming and Scripting

Korn Shell - Finding lowest number of a file.

I'm writing a KSH script that will get a file on the command line (such as input.txt), and in this file there is on number per line. The program needs to take the file, read each and determine the lowest number in the file. I currently have a while loop setup that will correctly out put every... (8 Replies)
Discussion started by: denyal
8 Replies

4. Shell Programming and Scripting

Extract the highest number out

Hi Gurus, I've using HPUX B.11.23 U ia64 with shell = sh. I've been having some problem get the highest number of this script. Actually I wanted to get the highest number from this listing (TEST123 data and based on this highest number, there will be email being sent out. For example,... (6 Replies)
Discussion started by: superHonda123
6 Replies

5. Shell Programming and Scripting

print every 20 lines the lowest number

Hello all, How can I find the lowest number every 10 lines? For example i have a list name1 -0.1 name2 2 name3 3 name4 -3 name5 1 name6 2 name7 34 name8 34 (6 Replies)
Discussion started by: TheTransporter
6 Replies

6. Shell Programming and Scripting

ksh program that finds the lowest number in a .txt file

i am having a problem finding the lowest number after punching in a bunch of numbers in the .txt file but its probably the way i have the code set up. help please! (4 Replies)
Discussion started by: tinsteer
4 Replies

7. Shell Programming and Scripting

Selecting lowest and highest values in columns 1 and 2, based on subsets in column 3

Hi, I have a file with the following columns: 361459 447394 CHL1 290282 290282 CHL1 361459 447394 CHL1 361459 447394 CHL1 178352861 178363529 AGA 178352861 178363529 AGA 178363657 178363657 AGA Essentially, using CHL1 as an example. For any line that has CHL1 in... (2 Replies)
Discussion started by: hubleo
2 Replies

8. Shell Programming and Scripting

top 10 highest and lowest percentile from a column

Hi, I want to extract the the top 10 and lowest 10 percentile for a column of values. For example in column 2 for this file: JOE 1 JAY 5 JAM 6 JIL 8 JIB 4 JIH 3 JIG 2 JIT 7 JAM 9 MAR 10 The top 10 lowest will be: JOE 1 and the top 10 highest will be: (2 Replies)
Discussion started by: kylle345
2 Replies

9. Shell Programming and Scripting

Perl: find next available lowest number that is available in two arrays

Hi there. I have a number allocation problem whereby I have 2 arrays built from 2 different sources. The arrays will just contain a listed of sorted numbers @a 1 7 10 14 15 16 @b 1 7 10 11 14 15 16 (2 Replies)
Discussion started by: hcclnoodles
2 Replies

10. 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
asort(1)						      General Commands Manual							  asort(1)

NAME
asort - Sorts or merges files and supports multiple collating weight sequences SYNOPSIS
asort [-m] [-o output_file] [-Abdfinruv] [-Ccollate_sequence] [-k keydef]... [-t character] [-T directory] [-y] [kilobytes] [-z record_size]... file... asort -c [-u] [-Abdfinruv] [-Ccollate_sequence] [-k keydef]... [-t character] [-T directory] [-y] [kilobytes] [-z record_size]... file... The following syntax is maintained for backward compatibility but may be withdrawn in a future release: asort [-Abcdfimnruv] [-Ccol- late_sequence] [-o output_file] [-t character] [-T directory] [-y] [kilobytes] [-z record_size] [+fskip] [.cskip] [-fskip] [.cskip] [-bdfinr]... file... OPTIONS
The asort command includes the same options as the sort command (see sort(1)) in addition to the following options: Specifies the collating weight sequence to be used in sorting the data files. When this option is specified, the asort command does not use the collating table from the locale database. Instead, the command uses a set of special system and user collating tables to determine the collating weights of characters, including user-defined characters (UDCs). The collate_sequence argument can be in long form (for example, "Pinyin Radical Stroke") or short form (for example, prs). The code- set of the locale determines which collation weight names can be specified for collate_sequence. The following list specifies the long and short collation weight names that are valid for supported codesets. For DEC Hanzi: Pinyon (or p) Radical (or r) Stroke (or s) For DEC Hanyu, Taiwanese EUC, and BIG-5: Phonetic (or p) Radical (or r) Stroke (or s) Uses a breadth-first sorting mechanism instead of the default depth-first mechanism to sort the input data. To have any effect, the -v option must be used together with the -C option. DESCRIPTION
The asort command sorts lines in its input files and writes the result to standard output. The asort command is similar to the sort com- mand. See the sort(1) reference page for information about features the two commands have in common. The asort command provides additional features for processing multiple collating weight sequences used with Asian languages, such as Chi- nese. For example, pinyon (p), stroke (s), and radical (r) are three dimensions along which characters can be ordered in Simplified Chi- nese. The -C option allows users to specify the priority level that these dimensions have during sorting. For example, -C srp specifies that characters should be sorted first by stroke, then by radical, then by pinyon. The specified sequence is applied to user-defined char- acters (UDCs) as well as to standard characters. When the -C option is specified, the default behavior of the asort command is to use a depth-first sorting mechanism to sort the input files. With the depth-first mechanism, pairs of multibyte characters in a sort field are compared by exhausting all the specified collat- ing weights and/or internal codes one at a time until the collating order is resolved. Only when two characters are identical is the next pair of characters compared. The depth-first sorting mechanism is also called character sorting. However, the asort command provides the -v option to use the Asian VMS-like breadth-first sorting mechanism. With the breadth-first mecha- nism, pairs of multibyte characters in a sort field are compared using the first collating weight for all the characters in the sort field first. Only when two sets of data in a sort field are computed to have the same collating order are succeeding collating weights used for resolving the collating order. The breadth-first sorting mechanism is sometimes called string sorting. NOTES
Currently, the asort command is supported for use only with Chinese codesets. EXIT STATUS
The asort command returns the following exit values: All input files were output successfully, or -c was specified and the input file was correctly sorted. If -c was specified, the file was not ordered as specified, or if the -c and -u options were both specified, two input lines were found with equal keys. An error occurred. EXAMPLES
Unless stated otherwise, the following examples assume the locale setting is zh_TW.dechanyu: To perform character sorting first by stroke and then by radical, enter: asort -C"Stroke Radical" names This command displays the lines in names sorted in ascending order according to the number of strokes in characters. If the number of strokes happen to be the same for two characters, the radicals of the characters determine how the characters are ordered.An alternative short form of the same command is as follows: asort -Csr names To perform string sorting first by stroke and then by radical in a way similar to the sort command available on an Asian VMS system, enter: asort -v -C"Stroke Radical" names SEE ALSO
Commands: sort(1) Functions: setlocale(3) Files: locale(4) Others: Chinese(5), i18n_intro(5) asort(1)
All times are GMT -4. The time now is 04:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy