Replace text in many files using perl
Last night, I have several files containing the same text and I wanted that text to be replaced. I used perl one liner to do the job and I thought it may be useful for someone else so here it is:
perl -e “s/text/replacewith/g;” -pi.orig *.txt
This is going to save a backup of the files with .orig extension and do the replace. If you don’t want backup, then remove the .orig from the line.
Also, if you want to replace text in all files in a directory, then use:
perl -e “s/text/replacewith/g;” -pi.orig $(find . -type f)
1 Comment
Other Links to this Post
RSS feed for comments on this post. TrackBack URI
By haythoo, February 23, 2010 @ 10:37 am
good work my dear friend, keep doing this, I love your how-to posts.