Please help re Perl script modification

R

Ron M.

I have a Perl script that searches through a directory and its
subdirectories and finds all files with a certain string in the
filename. Then it replaces some text in each of those files. The
script is below. This is how it would appear to operate on all ".html"
files, replacing "oldstring" with "newstring":

perl -i.bak -pe 's/oldstring/newstring/g' `find . -name *.html\*`

My question is this: the script creates a backup of EVERY file with
the suffix ".bak" and I don't want it to do this. How do I modify the
above script so that this won't happen?

Thanks,
Ron M.
 
G

Glenn Jackman

Ron M. said:
perl -i.bak -pe 's/oldstring/newstring/g' `find . -name *.html\*`

Not a perl issue. Missing backslash in your find command:
perl -i.bak -pe 's/oldstring/newstring/g' `find . -name \*.html`
 
B

Bob Walton

Ron said:
I have a Perl script that searches through a directory and its
subdirectories and finds all files with a certain string in the
filename. Then it replaces some text in each of those files. The
script is below. This is how it would appear to operate on all ".html"
files, replacing "oldstring" with "newstring":

perl -i.bak -pe 's/oldstring/newstring/g' `find . -name *.html\*`

My question is this: the script creates a backup of EVERY file with
the suffix ".bak" and I don't want it to do this. How do I modify the
above script so that this won't happen? ....


Ron M.

Let me see if I understand your question. You want to run the Perl
program on all the *.html* files, but you don't want to make *.bak
backup copies. If so, omit the .bak (and escape the first * ) [untested]:

perl -i -pe 'oldstring/newstring/g' `find . -name \*.html\*`

See:

perldoc perlrun

for details of the -i switch.
 
D

David Oswald

Ron M. said:
perl -i.bak -pe 's/oldstring/newstring/g' `find . -name *.html\*`

My question is this: the script creates a backup of EVERY file with
the suffix ".bak" and I don't want it to do this. How do I modify the
above script so that this won't happen?

s/\.bak//
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top