Friday, June 5, 2009

find and perl as alternative for sed

In continuation of my migration, some directories with HTML contents their are manually inputted by strings that would let a typical user to edit manually all the HTML files for just a sake of changing a text. However, Perl as an alternative for sed is quite helpful.

The command goes like this:

perl -e "s/www\.hawaiifsbos\.com/test\.hawaiifsbos\.com/g;" -pi $(find . -type f)

-p = will do a loop sequence. For more info, read the page in "Using the -n and -p option"
-i = will modify file in-place. providing after the "i" letter with a word, will be used as a back-up suffix of a file. (Ex. -pi.bak)
-e = means execute

This is the same thing as

find . -name "*.*" -type f -exec sed -i 's/www.mysite.com/test.mysite.com/g' {} \;

The above works in my Slack, but it seems weird it doesn't do in FreeBSD, but the perl is there as my alternative.

No comments: