Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keep only one line with the same value in column x 1

Status
Not open for further replies.

babcia01

IS-IT--Management
Jul 11, 2002
37
0
0
US
Hi,
I was trying with sort (uniq) but failed to get it.

The input file has this format

aaaa xxxxx
bbbb xxxxx
cccc xxxxx
dddd yyyyy
eeee yyyyy
ffff zzzzz

What command would I use to create a new output file and only keep one (highest) line with the same value in column 2.

I want to get:
aaaa xxxxx
dddd yyyyy

Thank you
 
I'm sure this can be done using the sort and awk command but i don't have access to a machine for now so i will come back to you once i try it. Meanwhile try looking in the man pages for these commands!

man sort

man awk

Regards,
Khalid
 
sort -k +2 -u filename

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Thank you. I tried with this syntax and it worked:
cat filename|sort -k 2,2 -u
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top