Quick Search:
 
 Perl Code: Remove Duplicate Lines from a File Jump to:  
Category: >> Perl Code >> Remove Duplicate Lines from a File  

<< 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)

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.";


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org