Replace text string in many files at once
By admin
So my boss says that he doesn't like the word “Admin” and wants it replaced with Administration in all the menus. Here's how to do it:
perl -p -i -e “s/'Admin'/'Administration'/g” *.rb
Perl rocks. Let's see you do that in Java!
Options explain:
-p assume loop like -n but print line also, like sed
-i edit <> files in place (makes backup if extension supplied)
-e one line of program (several -e's allowed, omit programfile)
Fortunately, with my case, the word “Admin” was surrounded by single quotes. If you have just the naked work Admin and you did:
perl -p -i -e “s/Admin/Administration/g” *.rb
two times in a row, you would end up with AdminAdministration, three times would give you AdminAdminAdministration…



August 25th, 2008
kenglish
August 18th, 2009
This can also be done with Sed:
sed -i ‘s/old-word/new-word/g’ *.txt