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

Leave a Reply