Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: how to check for a word in a file.. -- oneliner

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


in reply to Re: 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.
in thread 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.

Less tricky than the above oneliner version:
# file used below has the same content of the previous example's DATA +token<P> perl -e "open $fh,$ARGV[0];while(<$fh>){push @unv,$.-1,$.,$.+1 if /XXX +XX/}seek $fh,0,0;while(<$fh>){print unless ++$index ~~ @unv}" file 11111 22222 33333 44444

i was not able to resolve to use perl -lne because i've encountered some problem using seek ARGV even if in a BEGIN block.

L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found