in reply to Re: Delete Duplicate Entry in a text file
in thread Delete Duplicate Entry in a text file
Nice work, astronogun! However, there were just a couple of issues...
Did you really mean my $line == "fail.txt"? You used == instead of the assignment = and it needs to be done on a file handle: my $line = <$fh>
Without having changed your code too much, try the following:
use Modern::Perl; my $lastrow = ""; open my $fh, '<', 'fail.txt' or die $!; while (my $line = <$fh>) { $line =~ s/\n//g; next if !$line; if ($line ne $lastrow) { print $line, "\n\n"; $lastrow = $line; } } close $fh;
Output:
hostname1.com Gateway FAIL hostname2.com Gateway FAIL
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Delete Duplicate Entry in a text file
by sauoq (Abbot) on Jun 20, 2012 at 11:30 UTC | |
by Kenosis (Priest) on Jun 20, 2012 at 18:44 UTC | |
by sauoq (Abbot) on Jun 21, 2012 at 00:23 UTC | |
by Kenosis (Priest) on Jun 21, 2012 at 04:09 UTC | |
Re^3: Delete Duplicate Entry in a text file
by astronogun (Sexton) on Jun 20, 2012 at 06:32 UTC |