Siva Prasad wrote:

Hi Gurus,

Hello,

I want to remove duplicate lines across files.

Below is the detailed problem,


I have file1 file2,file3,file4,file5,

The lines in file1 are there in file2,file3,file4,file5  I want to remove
all the lines which are there in file1 from file2,file3,file4,file5.

Can anybody please tell me to solve the above problem?

UNTESTED:

#!/usr/bin/perl
use warnings;
use strict;

my $file = 'file1';

open my $fh, '<', $file or die "Cannot open '$file' $!";

my %lines;
@lines{ <$fh> } = ();

close $fh;

{   local ( $^I, @ARGV ) = qw/ .bak file2 file3 file4 file5 /;

    while ( <> ) {
        next if exists $lines{ $_ };
        print;
        }
    }

__END__



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to