|
|
Replacing all occurrences of a string in a group of files
|
|
|
|
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
Hey, everyone. I have a hierarchy of files and folders in which I would like to replace all in-file textual occurrences of "Template" with "PTemplate". Does anyone with more UNIX knowledge than I know of a command I can run that will do this for me?
Many thanks.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Dec 2000
Location: sj ca
Status:
Offline
|
|
I believe you want to do something like this:
Code:
perl -ip 's/Template/PTemplate' <files>
which replaces all string occurrences on all arg files "in-place". You might want to add a "backup" option for safety, like:
Code:
perl -i.bak -p 's/Template/PTemplate' <files>
Which makes a *.bak copy of all files.
To get all files:
Code:
perl -i.bak -p 's/Template/PTemplate' `find . -name '*'`
That's just off the top of my head; test before operating on real files.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
Thanks for the help, qyn.
I try to run any of those commands, though, and I always get:
Can't open perl script "s/Template/PTemplate": No such file or directory
What's wrong?
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jul 2002
Status:
Offline
|
|
You need the -e flag to Execute the argument as a program instead of a program name.
-i -p and -e often go together to make tasty perl -pie.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Dec 2000
Location: sj ca
Status:
Offline
|
|
Originally posted by Turias:
Thanks for the help, qyn.
I try to run any of those commands, though, and I always get:
Can't open perl script "s/Template/PTemplate": No such file or directory
What's wrong?
Oops!
You need the -e flag to Execute the argument as a program instead of a program name.
What he said .
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|