I have a list of files all over a file system e.g.
/home/1/foo/bar.x
/www/sites/moose/foo.txt
I'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g.
if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc.
There are around 120 substitutions and around 4,600 files.
One issue: these strings are passwords, I'm hoping not to need to escape them.
So far I've only come up with:
ggrep -HF -f /home/pass "/home/find-passwords/struc/www/sites/foo.php"
which doesn't do much except list the file and matched string from pass (which contains old passwords),
no escaping is required due to the -F arg to grep.
e.g.
ggrep -HF -f /home/pass "/home/find-passwords/struc/www/sites/foo.php"
returns:
/home/find-passwords/struc/www/sites/foo.php:$dbcnx = @mysql_pconnect("blah.com", "foo", "xfgt^5");
where xfgt^5 is the match from my /home/pass file.
I'm struggling with how to replace the old password with the new, and thinking loops with a bunch of ifs might work? Or a lookup table?
I can put the old and new passwords in a file with corresponding columns.
It would be nice to be able to run in a manner that shows what it will do, and then one that does it.
Thanks for any help,
Bill