find pattern in FILES and replace it ??


How can I looking for a pattern found in more than one file and replace it with anther pattern

this what I was used:

find . -name "account.adrs" -depth -follow -exec grep -l "Email = ;" {} \;

this print the files name -which is account.adrs- and its path -which is deferent for each file- which contains the pattern "Email = ;"

I need to replace this pattern by:
"Email = \"\" ;"

please help

There are a few ways to do this. One example:


FILES=`find . -name account.adrs -depth -follow -exec grep -l "Email = ;" {} \;`

for file in $FILES; do
perl -p i.bak -e 's/Email = ;/Email = \"\" ;/' $file

This generates an error for me "Can't open Perl script i.bak".

Does it mean we need a perl script named "i.bak" to do this task. I am not good at perl from command line.

here is another script. little modification from PxT's Script


FILES=`find . -name "account.adrs" -depth -follow -exec grep -l "Email = ;" {} \;`

for file in $FILES; do
sed -e 's/Email = ;/Email = \"\" ;/' $file > temp
mv -f temp $file

The i.bak is a directive to create backups of the original file with an extension of '.bak'. This helps insure that if you make mistake in your PERL filter, you have a backup of the original (always a good idea !). I did not check the exact syntax in the example code provided.

Thank you for info Neo.

error I made was, I put space between -p and i.bak.

it should be -pi.bak(without space) or -p -i.bak