Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: in place editing a list of files

by davidrw (Prior)
on Jan 07, 2007 at 17:09 UTC ( [id://593408]=note: print w/replies, xml ) Need Help??


in reply to in place editing a list of files

doesn't directly address your code issues, but here's a different approach that should do what you want from a bash prompt:
for f in `cat /home/rjs/heena/edit` ; do perl -i.bak -0777 -pe 's/CONFIDENTIAL(.*?)own\s+risk/ /s' $f done
Update: shell-independent method: perl -i.bak -0777 -pe 's/CONFIDENTIAL(.*?)own\s+risk/ /s' `cat /home/rjs/heena/edit`

If the 'edit' file contains a list of directories (i wasn't entirely sure from your post), then:
for d in `cat /home/rjs/heena/edit` ; do perl -i.bak -0777 -pe 's/CONFIDENTIAL(.*?)own\s+risk/ /s' $d/* done
See perlrun for info on the various switches (the -0777 causes a slurp).

Replies are listed 'Best First'.
Re^2: in place editing a list of files
by rjsaulakh (Beadle) on Jan 08, 2007 at 18:39 UTC

    davidrw hats of to u sir

    shell-independent method: perl -i.bak -0777 -pe 's/CONFIDENTIAL(.*?)own\s+risk/ /s' `cat /home/rjs/heena/edit`

    you single line of code has done all the magic . just one more update i require from u , will this piece of code work fine when incorporated with another perl script

      depends what "incorporated" means ..

      does this need to be invoked from inside another script? if so obviously just can't copy/paste verbatim (could dump it in a system call, though maybe not ideal method) ..

      or does this just need to be called right before/after another perl script? if so, could just wrap the two calls in a shell script ...

      otherwise, write a sub that sets $^I, @ARGV, $/, and runs the loop that -n or -p does (see perlrun)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-29 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found