in reply to Re: Remove duplicate lines in a file
in thread Remove duplicate lines in a file

Thanks! that was great. But just a quick thought if at all I like to remove the first entry (40087) in some case? Do I need to sort the file first by the 4th column and proceed ? Or is there any better way of doing it? Once again, Thanks a lot for your reply.

Replies are listed 'Best First'.
Re^3: Remove duplicate lines in a file
by RhetTbull (Curate) on Nov 05, 2008 at 18:14 UTC
    I'm not sure I understand the question. I think you're asking how to print the last entry instead of the first. This code should do that:
    use strict; use warnings; my $last_key = undef; my $last_line = <>; #get first line while(<>) { my $key = (split)[0]; if (defined $last_key && $key ne $last_key) { #new key, print the last line from the old key print $last_line; } $last_line = $_; $last_key = $key; } print $last_line; #very last entry won't get printed in the while loop