Hi monks, I have written a perl script for reading an input file and checking if there are certain keywords present in that file and remove those lines from the file.
How do I modify the perl script to remove the one line above and below the line I am removing currently,as well as remove the line containing XXXXX.#!/usr/bin/perl use strict; use warnings; open(my $in, '<', 'out2.txt') or die "Cannot open input.txt: $!"; open(my $out, '>', 'out2_mod.sp') or die "Cannot open output.txt: $!"; while (<$in>) { print $out $_ unless /XXXXX/; } close($in); close($out);
To rephrase. my input file will have
I want to find the lines were XXXXX exists and remove the line above and below that line and also line containing XXXXX. So my ouptut should look likePPPPP XXXXX is my name YYYYY KKKKK UUUUU BBBBB CCCCCC XXXXX is what I play KKKKK NNNNN
KKKKK UUUUU BBBBB NNNNN
In reply to how to check for a word in a file and if found remove that line, the above line and the below line from the file. by Ganesh Bharadwaj1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |