Jun 15 2010

Replace a text pattern on multiple files recursively

Category: Linuxguillem @ 8:41 PM

Today we’re going to look at something similar to what i wrote a while ago, but more specific. In fact, we are going to specify the filname and the string to find:

grep -r –include=your_filename -l “patter_to_search” . | xargs perl -pi.bak -e ‘s/pattern_to_search/replacement_string/g’

I think the names are selfexplainatory  ;)

In addition, this creates a backup copy just in case we do something wrong….

Tags: , , ,