Last Updated: February 25, 2016
·
841
· padawin

Search and replace with Perl in command line

Search and Replace in one or multiple files

Single file:

perl -pi -e 's/%SEARCHED_VALUE%/%REPLACE_VALUE%/g' file

Multiple files:

files | xargs -I[] perl -pi -e 's/%SEARCHED_VALUE%/%REPLACE_VALUE%/g' []

example:

```bash
ls *.txt | xargs -I[] perl -pi -e 's/%SEARCHED_VALUE%/%REPLACE_VALUE%/g' []

Search and Replace in files and directories names

rename 's/%SEARCHED_VALUE%/%REPLACE_VALUE%/' files