in reply to Re^3: how to change this code into perl
in thread how to change this code into perl
Thank you very much Laurent_R, I tried the script and its printing all the rows, instead of duplicates. Laurent_R, this code looks very interesting, can you please explain it
#!/usr/bin/perl my ($previous_key, $previous_line); open my $IN, "<", '/home/scripts/imageoutcome.txt' or die "cannot open + $infile $!"; while (<$IN>) { my $key = $1 if /^(\w+)/; if ($key eq $previous_key) { print $previous_line if defined $previous_line; print $_; undef $previous_line; } else { $previous_line = $_; } $previous_key = $key; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: how to change this code into perl
by Laurent_R (Canon) on Aug 31, 2015 at 10:47 UTC |