Replace word from multiple files in linux/unix using grep and perl

for single file.

perl -pi -e ’s/OLDCHAR/NEWCHAR/g’ filename.txt

For multiple files.

grep -R –files-with-matches ‘OLDCHAR’ . | sort | uniq | xargs perl -pi~ -e ’s/OLDCHAR/NEWCHAR/g’

Thanks,

Jayesh

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)