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

output only unique lines, no duplicates 3

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
Hello, I have the following input file.

Sri Lanka v Pakistan
England v West Indies
Sri Lanka v Pakistan
West Indies A v India A
England v West Indies
West Indies A v India A
England v West Indies
West Indies A v India A
Sri Lanka v Pakistan
England v West Indies
West Indies A v India A
Sri Lanka v Pakistan
Zimbabwe Twenty20 Triangular Series
West Indies A v India A
England v West Indies
Zimbabwe Twenty20 Triangular Series
Sri Lanka v Pakistan
England v West Indies
Zimbabwe Twenty20 Triangular Series

I need to only output unique lines as below.

Sri Lanka v Pakistan
England v West Indies
West Indies A v India A
Zimbabwe Twenty20 Triangular Series

Please note that I cant use "sort | uniq" as the order needs to be maintained.

Thanks
Arun
 
Hi

Code:
awk '[teal]![/teal]s[teal][[/teal][navy]$0[/navy][teal]];[/teal][teal]{[/teal]s[teal][[/teal][navy]$0[/navy][teal]]=[/teal][purple]1[/purple][teal]}[/teal]' /input/file
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
[link feherke.github.com/][/url]
 
Hi Feherke,

Thanks! That works great!!

Arun
 
sort -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."
 
Why not simply this ?
Code:
awk '!x[$0]++' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
mrn,

Thanks for your post. I cant sort as I need to maintain the order, meaning the first occurrence of a string must remain in its original position.

PH,

Your 'awk' statement works great. Appreciate it!

Thanks,
Arun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top