Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: how to check for a word in a file and if found remove previous and next -- 3 oneliner variations

by Discipulus (Canon)
on Jan 26, 2016 at 11:50 UTC ( [id://1153667]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # $y is <C>yet</C> set for the second read, @u is <C>unwanted</C> <P>
    
    ...
    33333
    44444<P>
    
  2. or download this
    perl -lnE "BEGIN{$r=shift;$r=qr/$r/;$n=shift@ARGV;push @ARGV,$ARGV[0]}
    +eof&&!$y?$y=close ARGV:/$r/&&!$y?push @u,$.-$n..$.+$n:$y&&!($.~~@u)?s
    +ay:0" XXXXX 1 next-and-previous.txt
    11111
    ...
    perl -lnE "BEGIN{$r=shift;$r=qr/$r/;$n=shift;push @ARGV,$ARGV[0]}eof&&
    +!$y?$y=close ARGV:/$r/&&!$y?push @u,$.-$n..$.+$n:$y&&!($.~~@u)?say:0"
    + XXXXX 2 next-and-previous.txt
    22222
    
  3. or download this
    perl -slnE "BEGIN{$r=qr/$r/;push @ARGV,$ARGV[0]}eof&&!$y?$y=close ARGV
    +:/$r&&!$y?push@u,$.-$n..$.+$n:$y&&!($.~~@u)?say:0"  
               -- -r=XXXXX -n=1 next-and-previous.txt
    ...
    33333
    44444
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1153667]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found