tamer
February 28, 2001, 9:29am
1
Hi
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
PxT
February 28, 2001, 11:38am
2
There are a few ways to do this. One example:
#!/bin/ksh
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
done
mib
March 1, 2001, 9:22am
3
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
#!/bin/sh
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
done
Neo
March 1, 2001, 10:03am
4
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.
mib
March 3, 2001, 9:30am
5
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