Help with keep the largest record in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with keep the largest record in file
# 1  
Old 08-25-2011
Help with keep the largest record in file

Input file
Code:
US	Score	10
UK	Ball	20
AS	Score	50
AK	Ball	10
PZ	Ballon	50
PA	Score	70
WT	Data	10
.
.

Desired output file
Code:
UK	Ball	20
PZ	Ballon	50
PA	Score	70
WT	Data	10
.
.

Condition:
1. If the column 2 is same, keep the record that have largest number in column 3.
Thanks for advice.
# 2  
Old 08-25-2011
Code:
awk '$3>m[$2]{m[$2]=$3;a[$2]=$0}END{for(i in a)print a[i]}' file

This User Gave Thanks to bartus11 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

2. Shell Programming and Scripting

awk second largest, third largest value

I have two text files like this: file1.txt: 133 10 133 22 133 13 133 56 133 78 133 98 file2.txt: 158 38 158 67 158 94 158 17 158 23 I'm basically trying to have awk check the second largest value of the second column of each text file, and cat it to its own text file. There... (13 Replies)
Discussion started by: theawknewbie
13 Replies

3. Shell Programming and Scripting

To Find the largest file in the given directory.

Hi Experts, 1. In unix how to list the largest file in given directory. The answer will in single line statement. 2. I have Sun solaris live CD .I try to compile sample c program using "CC compiler".But its shows "cc command not found". Please help on this. Thanks in advance.... (4 Replies)
Discussion started by: kkl
4 Replies

4. Shell Programming and Scripting

Command to find largest file.

Hi All, Is there a direct Linux command to find the largest file by checking recursively in all the directories. (3 Replies)
Discussion started by: paragkalra
3 Replies

5. UNIX for Dummies Questions & Answers

largest file

My directory only contains files..no sub directories..I want to know about the largest file in directory..Largest in terms of size..And what if I want to know about first 3 largest files.. Is it possible to know largest file in terms of its filename?? (4 Replies)
Discussion started by: aadi_uni
4 Replies

6. HP-UX

find the largest file in whole system

find the largest file in whole system (7 Replies)
Discussion started by: megh
7 Replies

7. Shell Programming and Scripting

largest value from within a file

hi, i am having a file that looks like this : myhome111 oper 11 myhome333 oper 19 ... how can i get the largest value from this file ..in this example i am consiering 19 as the largest value.. how can i do that.. as this file is having other numbers also within it like 111, 333... (4 Replies)
Discussion started by: kripssmart
4 Replies

8. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies

9. Shell Programming and Scripting

find largest file

Hi, 1)I have XX directory and have lot of files ,I want to find largest file in that directory 2)how calculate the size of file in MB. Thanks, Mohan (15 Replies)
Discussion started by: mohan705
15 Replies

10. Shell Programming and Scripting

file of largest size in pwd

How to find file of the largest size in pwd? (4 Replies)
Discussion started by: rameshparsa
4 Replies
Login or Register to Ask a Question