system
1
Say I am in /var/adm/bin and I want to search through all the various scripts and such in that directory for a string, say, xxx@yyy.com
I want to find every file with that in there and replace it with a single space.
Is that possible?
Or, is it possible to search every file and get a list of what files have that in there?
If I do a more * | grep xxx@yyy.com I get a list of all the lines with that in there but no reference to the file name.
Anyone have any ideas?
i just read the original post ...
this is in ksh ...
for file in `grep -l xxx@zzz.com *`
do
sed "s/xxx@zzz.com/ /g" $file > /tmp/123
cat /tmp/123 > $file
rm /tmp/123
done
perl:
$ perl -pi -e 's|bar\@mydomain.com||g' *
use -pi.bak if u need to backup your original files (will renamed as .bak)
or:
#!/bin/ksh
for i in $(grep -l 'xxx@zzz.com' *)
do
(/bin/echo '%s/xxx@zzz.com/ /g\nwq!') | ex - ${i}
done;
This wont work if you have subdirectories with files inside them.
In which case you could use something like this:
grep "pattern" `find /path -name * -print`
you're right, but read the original post, pls!