in reply to Re^3: Delete Duplicate Entry in a text file
in thread Delete Duplicate Entry in a text file
Thank you for your thoughts. My intent was to produce the OP's requested output w/o doing too much to the original code for the sake of a differentiated learning experience.
I tried your suggestions as follows on the OP's data set:
use Modern::Perl; my $lastrow = ""; open my $fh, '<', 'fail.txt' or die $!; while (my $line = <$fh>) { next unless $line =~ /\S/; if ($line ne $lastrow) { print $line; $lastrow = $line; } } close $fh;
Output:
hostname1.com Gateway FAIL hostname2.com Gateway FAIL Gateway FAIL
Unless I've misunderstood your re-coding suggestions, they do not produce the OP's desired outcome. (Using say instead of print produces the desired line spacing, but the last string is repeated.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Delete Duplicate Entry in a text file
by sauoq (Abbot) on Jun 21, 2012 at 00:23 UTC | |
by Kenosis (Priest) on Jun 21, 2012 at 04:09 UTC |