[Howto] [Linux] [Programming] [Tips and Tricks]
Linux tip: How to replace text in multiple files
Don't want to miss a single bit? Subscribe to our RSS Feed!
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' *.txtOr 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/'Good luck! It saves a lot of time and it is excellent tip for every advanced Linux user!
Did you enjoy this post? Why not leave a comment below and continue the conversation, or Subscribe to Feed and get articles like this delivered automatically to your Email or feed reader.
0 comments:
Post a Comment