Ganesh Bharadwaj1 has asked for the wisdom of the Perl Monks concerning the following question:
I would like to know how to delete a line and the next line if they occur in order.
As in Assume
First line is cat
second line is dog.
If cat is followed by dog in the preceding line, I want to delete both lines.
But if dog is followed by cat, I want to keep both the lines.
for instance if input file (input.txt) hasthe output file (output.txt) will be will bedog cat dog dog cat goat
I think I should buffer some lines, but I am not sure how to proceed. Any help will be greately appreciated.dog dog cat goat
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: If line is followed by line, delete both lines
by Athanasius (Archbishop) on Sep 15, 2016 at 07:16 UTC | |
|
Re: If line is followed by line, delete both lines
by Marshall (Canon) on Sep 15, 2016 at 07:03 UTC | |
|
Re: If line is followed by line, delete both lines
by Marshall (Canon) on Sep 15, 2016 at 09:09 UTC | |
|
Re: If line is followed by line, delete both lines
by Anonymous Monk on Sep 15, 2016 at 14:31 UTC |