Getting Unique values from a file with Perl
I have a flat tab delimited file. Each line has a field with categories in it. But there may be dups. Like so...
Category 1
Category 2
Category 2
Category 3
Category 3
I need to generate a list that has only unique values. Like this...
Category 1
Category 2
Category 3
Is there a command for Perl I can use. I know I could loop through the values if they are sorted by the category and check each to see if the current value matches the last and if not add it to an array. I thought that some of you may know a simpler way. Any help would be great.
Thanks,
G
Thanks
G
Wil posted this at 20:14 — 6th October 2002.
They have: 601 posts
Joined: Nov 2001
No, that is the simplest way. The only other way I know of would be to throw them all into an array and grep the array for identical matches. But doing this would be inefficent use of grep, so I'd opt for the loop option you first considered.
- wil
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.