Replacing same text in multiple files

0 Flares Facebook 0 Twitter 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

If you have text you want to replace in multiple locations, there are several ways to do this. To replace the text Windows with Linux in all files in current directory called test[something] you can run this:

perl -i -pe 's/Windows/Linux/;' test*

To replace the text Windows with Linux in all text files in current directory and down you can run this:

find . -name '*.txt' -print | xargs perl -pi -e's/Windows/Linux/ig' *.txt

Or if you prefer this will also work, but only on regular files:

find -type f -name '*.txt' -print0 | xargs --null perl -pi -e 's/Windows/Linux/'

You Can use "sed" also

sed -i 's/piyushk/piyush/g' file_name

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *