Solved

Simple Perl Script to get Unique values from file

Posted on 2011-03-21
2
460 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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