sed – is useful to find and replace text in single multiple files.

* Replacing foo with foo_bar in a single file.

sed -i ’s/foo/foo_bar/g’ somefile.module

o -i = tell sed to edit the file(s)
o s = substitute the following text
o foo = what you want to substitute
o foo_bar = what you want to replace
o g = global, match all occurrences in the line
* Replacing foo with foo_bar in a multiple files.

sed -i ’s/foo/foo_bar/g’ *.module

* Now you can run cvs diff -up > yourpatchfile.patch to create a patch.

Here is the sample: I always make the complex situation and resolve!

find . -name “*” ‘ xargs file ‘ grep -v directory ‘ grep -v image ‘ cut -d’:’ -f1 ‘ xargs sed -i “s/Santa Clara/San Jose/g”

This one finds all the files in current and below directories (find . -name “*”)

finds the file type (xargs file)

Strips the directories and images ( grep -v directory ‘ grep -v image )

Cuts the first part, delimiter colon, only for file name ( cut -d’:’ -f1 )

finally changes the all the files strings ( xargs sed -i “s/Santa Clara/San Jose/g” )

find . -name “*” ‘ xargs file ‘ grep -v dire ‘ grep -v image ‘ cut -d’:’ -f1 ‘ xargs sed -i “/Country :/d”

The above deletes the matching line “Country :” in all the files

Recent substitutions I made:
find . -name “*” ‘ xargs file ‘ grep -v directory ‘ grep -v image ‘ cut -d’:’ -f1 ‘ xargs sed -i “s/jkstablemid/dlg_outer/g”find . -name “*” ‘ xargs file ‘ grep -v directory ‘ grep -v image ‘ cut -d’:’ -f1 ‘ xargs sed -i “s/jkstablelow/dlg_inner/g”if (document.currentScript) {