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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I remove duplicate values?

Status
Not open for further replies.

whatisthis987

IS-IT--Management
Apr 24, 2007
34
US
Thanks in advance for any help. What I want...

Input file:
John line1
John line2
John line3
Mary line4
Mary line5
Walter line6
Jack line7
Jack line8

Output file:
John line1
line2
line3
Mary line4
line5
Walter line6
Jack line7
line8


Keep everything in $2 the same. Only remove duplicates in $1.
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tried uniq -u but it returns the same as the input file. This is becuase it compares lines instead of the fields.
 
I'd use awk

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I would do it something like this:

Code:
awk '$1==p {$1=" "} {print; p=$1}' inputfile > outputfile


Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top