Tip: Remove Duplicate Lines in File Using Perl
Here is little nifty code I found to snip or remove duplicate lines in a file using Perl. An example of a file that has duplicate lines looks like this:
/home/index.php
/home/links.php
/home/index.php
The result we want to achieve is this:
/home/index.php
/home/links.php
And here goes the code:
$ftmp = 'file.txt';
my %match = ();
{
local @ARGV = ($ftmp);
local $^I = '.tmp';
while(<>){
$match{$_}++;
next if $match{$_} > 1;
print;
}
}
The original file, file.txt, has its duplicate lines removed.
Related Posts
3 Comments to “Tip: Remove Duplicate Lines in File Using Perl”
Post comment
Search PinoyTux
Subscribe to Email Feeds
Blog Lounge
Popular Posts
Recent Posts
Drop your Card Here
Recent Comments
- Eduardo Portillo on 3ix Scam: Looking for Feedbacks
- wayne donahue on Cebu Pacific Airlines is Evil!
- smeaferrepove on Howto: Install yum On RHEL 4
- Anidich1 on Tip: Add User and Generate Password Script
- Tom S on Cebu Pacific Sucks









hai,
good morning, anybody is there
hai
good morning, anyody is there
@Saravanan: go ahead dude, we’re all ears !