Go to content Go to navigation & search

welcome to weekeat.com

Navigation

navigation

feeds

choose: rss / atom


Content

Perl: One line search and replace

posted 10 May 2007

Yes, it’s been used for a long long time and I have been using them for quite a while too. But the problem is, I always forget which one to leave out for a dry run. So, I’m putting it here as a quick ref in the future.

For search and replace applied to files specified:

me@mycomp:~$ perl -pi -e ‘s/search/replace/g’ *.html

For non-applied search and replace (without the i argument):

me@mycomp:~$ perl -p -e ‘s/search/replace/g’ something.html

There you go. If you have a bad memory like mine, you can bookmark this page for a quick ref too.

The way I try to use now to remember which one to exclude is this:
-pi means print into as in print into the file(s) searched and p means print only [to screen].

Have fun!

 

Got something to say?

  Textile Help