Maximum value of each line entry


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Maximum value of each line entry
# 1  
Old 03-16-2009
Maximum value of each line entry

Dear power users,

I have a file like this:

AA 8
AA 6
AA 5
AA 4
AA 3
BB 9
BB 4
BB 3
BB 2
ZZ 5
ZZ 3
ZZ 1
...
The characters in colum one are variously different until the end of the file. I want to extract the maximum value of each entry in column one, so the output will be like this:

AA 8
BB 9
ZZ 5
...

Anybody could help me to made the script, since the file consist of about 10.000 lines? I have search in the rest of the forum, but found no clue. Tx
# 2  
Old 03-16-2009
Code:
sort -t" " -k 1,1 -k2,2r infile| awk 'a != $1 {a=$1; print $0; next}'
AA 8
BB 9
ZZ 5

# 3  
Old 03-16-2009
Ok..Tx very much for the enlightenment :-)
# 4  
Old 03-16-2009
Another approach:

Code:
awk 'a[$2]<$2{a[$2]=$2} END{for(i in a){print i, a[i]}}' file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Maximum length of a line

How can I change the maximum length of a programming line in fortran and C (specifically in fortran 77)? Seems the default maximum length is 72 in fortran 77. Thanks. (4 Replies)
Discussion started by: hbar
4 Replies

2. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

3. Shell Programming and Scripting

Searching for an entry and deleting the line

Hi Im trying to scan a file for certain entries and remove their corresponding lines completely. What I have now is this, for USER in user1 user2 user3 user4 do sed '/$USER/d' /etc/sudoers done However this doesn't remove the entries at all. Is there another way for this? Thanks... (2 Replies)
Discussion started by: bludhemn
2 Replies

4. Shell Programming and Scripting

How to edit file to have one line entry?

Hello All, My file content is: DROP TABLE "FACT_WORLD"; CREATE TABLE "FACT_WORLD" ( "AR_ID" INTEGER NOT NULL, "ORG_ID" INTEGER NOT NULL ) DATA CAPTURE NONE COMPRESS YES; I want to change this file to have entries in one... (6 Replies)
Discussion started by: akash2508
6 Replies

5. Shell Programming and Scripting

Maximum command line arguments

Hi, Can anyone please help me to know what is the maximum number of command line arguments that we can pass in unix shell script? Thanks in advance, Punitha.S (2 Replies)
Discussion started by: puni
2 Replies

6. Shell Programming and Scripting

Maximum number of characters in a line.

Hi, Could any one please let me know what is the maximum number of characters that will fit into a single line of a flat file on a unix. Thanks. (1 Reply)
Discussion started by: Shivdatta
1 Replies

7. UNIX for Dummies Questions & Answers

what is the maximum length of th os-command line in Unix.

Hi All, I didn't find any thread that match this question so I hope it's not redundant. I am totally new to Unix. I want to know what is the maximum length of the os-commandline in Unix. Will it cause any problem if I run any application whose total path length is much longer than 256... (2 Replies)
Discussion started by: kumardesai
2 Replies

8. UNIX for Dummies Questions & Answers

Remove duplicate entry in one line

Can anyone help me how can i print only the unique entry in a line? MI_AP MI_AP MI_CM MI_MF RC_NAP MBS_AP SF_RAN MBS_AP NT_CAR so that it will on output the one unique entry per line. MI_AP MI_CM MI_MF RC_NAP MBS_AP SF_RAN NT_CAR I can't find the same situation on the knowledge... (5 Replies)
Discussion started by: kharen11
5 Replies

9. Shell Programming and Scripting

Line with maximum no . of characters

Hey , I want to check the row in a file with maximum characters . the output sud contain that row number along with the no of characters. (4 Replies)
Discussion started by: mohapatra
4 Replies

10. UNIX for Advanced & Expert Users

Print the line containing the maximum value in a column

Dear all! I want to find the maximum value in two specific columns with numbers, and then print the entire line containing this value. The file may look like: 1001 34.5 68.7 67 1002 22.0 40.1 32 1003 11.3 34.8 45 I want to find the maximum value within column 2... (22 Replies)
Discussion started by: kingkong
22 Replies
Login or Register to Ask a Question