How to only display lines where a field has the highest number?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to only display lines where a field has the highest number?
# 1  
Old 08-05-2010
Question How to only display lines where a field has the highest number?

Hello

Wondering if anybody can advise me how I can sort the below file so it only displays lines with the latest versions of an object? As you'll see some of the scripts listed in my file have more than one version number (version number is after the file extension). E.g. cdm_bri.pkb has versions 1 - 6 listed I only want to see the line showing verson 6. I've searched the forum for similar threads, but haven't been able to find what I'm looking for.

Many thanks
Glyn

Code:
 
breach_repetitions_pop.sql-1           85820       SRDP_BREACHES/1
breach_repetitions_pop.sql-2           86628       SRDP_BREACHES/1
breach_repetitions.tab-1               85820       SRDP_BREACHES/1
breach_repetitions.tab-2               86628       SRDP_BREACHES/1
breach_reporting_orgs_pop.sql-1        85820       SRDP_BREACHES/1
breach_reporting_orgs_pop.sql-2        86628       SRDP_BREACHES/1
breach_reporting_orgs.tab-1            85820       SRDP_BREACHES/1
breach_reporting_orgs.tab-2            86628       SRDP_BREACHES/1
breach_severities_pop.sql-1            85820       SRDP_BREACHES/1
breach_severities_pop.sql-2            86628       SRDP_BREACHES/1
breach_severities.tab-1                85820       SRDP_BREACHES/1
breach_severities.tab-2                86628       SRDP_BREACHES/1
breaches_br_iu.trg-1                   85820       SRDP_BREACHES/1
breaches_br_iu.trg-2                   86628       SRDP_BREACHES/1
breaches_fk.con-2                      85820       SRDP_BREACHES/1
breaches_fk.con-3                      86628       SRDP_BREACHES/1
breaches_qry_api_pkg.pkb-3             85821       SRDP_BREACHES/1
breaches_qry_api_pkg.pkb-4             87266       SRDP_BREACHES/1
breaches_qry_api_pkg.pks-3             85821       SRDP_BREACHES/1
breaches_qry_api_pkg.pks-4             87266       SRDP_BREACHES/1
breaches_upd_api_pkg.pkb-1             87266       SRDP_BREACHES/1
breaches_upd_api_pkg.pks-1             87266       SRDP_BREACHES/1
breaches.tab-2                         85820       SRDP_BREACHES/1
breaches.tab-3                         86628       SRDP_BREACHES/1
cdm_bes.pkb-3                          85821       SRDP_BREACHES/1
cdm_bes.pkb-4                          86589       SRDP_BREACHES/1
cdm_bes.pkb-5                          87101       SRDP_BREACHES/1
cdm_bes.pkb-6                          87152       SRDP_BREACHES/1
cdm_bes.pks-3                          85821       SRDP_BREACHES/1
cdm_bes.pks-4                          86589       SRDP_BREACHES/1
cdm_bilp.pkb-1                         85821       SRDP_BREACHES/1
cdm_bilp.pkb-2                         86589       SRDP_BREACHES/1
cdm_bilp.pkb-3                         87017       SRDP_BREACHES/1
cdm_bilp.pks-1                         85821       SRDP_BREACHES/1
cdm_bilp.pks-2                         86589       SRDP_BREACHES/1
cdm_bre.pkb-3                          85821       SRDP_BREACHES/1
cdm_bre.pkb-4                          87160       SRDP_BREACHES/1
cdm_bre.pkb-5                          87171       SRDP_BREACHES/1
cdm_bre.pks-3                          85821       SRDP_BREACHES/1
cdm_bre.pks-4                          87171       SRDP_BREACHES/1
cdm_bri.pkb-1                          85821       SRDP_BREACHES/1
cdm_bri.pkb-2                          87017       SRDP_BREACHES/1
cdm_bri.pkb-3                          87174       SRDP_BREACHES/1
cdm_bri.pkb-4                          87180       SRDP_BREACHES/1
cdm_bri.pkb-5                          87184       SRDP_BREACHES/1
cdm_bri.pkb-6                          87260       SRDP_BREACHES/1

# 2  
Old 08-05-2010
Code:
awk -F'[ -]' ' { if(!a[$1] || a[$1]<$2){ a[$1]=$2;arr[$1]=$0 } } END { for(i in arr){ print arr[i] } } ' file

This User Gave Thanks to anbu23 For This Post:
# 3  
Old 08-05-2010
Thanks, that's doing exactly what I'm wanting!

I need to read up a bit more on this though. I take it, I need to be looking arrays in AWK?

Many thanks
Glyn
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort from highest to lowest number

Hi Guys, I am looking for a way to sort the output below from the "Inuse" count from Highest to Lowest. Is it possible? Thanks in advance. user1 0.12 0.06 0 0.12 User Inuse Pin Pgsp Virtual Unit:... (4 Replies)
Discussion started by: jaapar
4 Replies

2. Shell Programming and Scripting

Printing uniq first field with the the highest second field

Hi All, I am searching for a script which will produce an output file with the uniq first field with the second field having highest value among all the duplicates.. The output file will produce only the uniqs which are duplicate 3 times.. Input file X 9 B 5 A 1 Z 9 T 4 C 9 A 4... (13 Replies)
Discussion started by: ailnilanjan
13 Replies

3. Shell Programming and Scripting

Only print the entries with the highest number?

Just want to say this is great resources for all thing Unix!! cat tmp.txt A 3 C 19 A 2 B 5 A 1 A 0 C 13 B 9 C 1 Desired output: A 3 B 9 C 19 The following work but I am wondering if there is a better way to do it: (4 Replies)
Discussion started by: chirish
4 Replies

4. UNIX for Advanced & Expert Users

query display number lines or records present in file only numeric value -without filename

Hi all Thanks in advance........... Please help me for this issue............ I have a file it has 11 records . I used the command like .... >$ wc -l file 11 file I'm getting output like 11 file (no.of records along with filename) here my requirement is, I want to display only... (3 Replies)
Discussion started by: ksrivani
3 Replies

5. UNIX Desktop Questions & Answers

How to display only the lines from a file which do not contain a given number

a. How do I display the content of the file containing what Ive merged using a filter which would display only the lines of the file which don't contain number, for example 3 or 6. (3 Replies)
Discussion started by: herberwz
3 Replies

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

7. Shell Programming and Scripting

Displaying lines of a file which have the highest number?

Hello Wondering if anybody may be able to advise on how I can filter the contents of the following file: <object_name>-<version> <Instance> GM_GUI_code.fmb-4 1 GM_GUI_code.fmb-5 1 GM_GUI_code.fmx-4 ... (7 Replies)
Discussion started by: Glyn_Mo
7 Replies

8. Shell Programming and Scripting

How to match all array contents and display all highest matched sentences in perl?

Hi, I have an array with 3 words in it and i have to match all the array contents and display the exact matched sentence i.e all 3 words should match with the sentence. Here are sentences. $arr1="Our data suggests that epithelial shape and growth control are unequally affected depending... (5 Replies)
Discussion started by: vanitham
5 Replies

9. UNIX for Dummies Questions & Answers

display lines after a particular line number

I have a file that has 1k lines and i want to print all the lines after 900th line. an 2)I want to move files f1 ,f2,f3,f4 to p1,p2,p3,p4 Please give me the commands. Thanx in adv. (6 Replies)
Discussion started by: rajashekar.y
6 Replies

10. Shell Programming and Scripting

find the highest number in the file

Hi, I have a file a.txt and it has values in it Eg :- I need to read through the file and find the number that is the greatest in them all. Can any one assit me on this. Thanks (30 Replies)
Discussion started by: systemali
30 Replies
Login or Register to Ask a Question