Solved

Simple Perl Script to get Unique values from file

Posted on 2011-03-21
2
441 Views
Last Modified: 2012-06-21
It has been a few years since I have used Perl.  I have a text file with about 400 entries.  There are duplicates in the file.  An example of the input file would be.

smith
jones
taylor
smith
bruce

I need a output file with only the unique values.  An example of the output file

smith
jones
taylor
bruce

order is not important - I just need the unique values

0
Comment
Question by:jkteater
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 35183290
see
perldoc -q duplicate

perl -lne 'print unless $seen{$_}++' <inputfile > outputfile
0
 

Author Closing Comment

by:jkteater
ID: 35183386
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now