CoderZone.org

Category: >> Perl Code >> Remove Duplicate Lines from a File Bookmark and Share

<< lastnext >>

Snippet Name: Remove Duplicate Lines from a File

Description: A quick and easy code snippet to remove duplicate lines from a file.

Comment: (none)

Author: CoderZone
Language: PERL
Highlight Mode: PERL
Last Modified: March 05th, 2009

#!/usr/bin/perl
 
use strict;
use warnings;
 
my $file = '/path/to/file.txt';
my %seen = ();
{
   local @ARGV = ($file);
   local $^I = '.bac';
   while(<>){
      $seen{$_}++;
      next if $seen{$_} > 1;
      print;
   }
}
print "finished processing file.";
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 36