I've found this script which seems very promising to solve my issue:
To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem.
The passwords may or may not be contained within quotes, single quotes, etc.
#!/bin/bash
f="passwords.csv"
find /path -type f -name "*.txt" | while read FILE
do
awk 'BEGIN{ FS="," }
FNR==NR{ s[$1]=$2; next }
{
for(i in s){
if( $0 ~ i ){ gsub(i,s) }
}
print $0
}' $f $FILE > temp
mv temp $FILE
done
My passwords.csv file contains old passwords and new ones, comma delimited. I've altered the find command within this script to find the files I want.
The script works if the first column (old password) has no special characters, but since these are passwords, there are lots of special characters.
It seems the second column (new password) can contain special characters ...
I've tested this by having the find command (within the script) find a specific file, with a password that has no special characters, and using a test passwords.csv with the non-special password (in the first column), and the new password (in the second column) having special characters, and it does the substitution.
However, if the reverse is true (and in most cases it is), I receive the error:
Is there something I can do to the script that will treat both columns (or matches), as literals? I say matches because I'm actually not sure if it is my passwords.csv file containing the special character password, or the file that contains it, that is breaking this. Whatever it is, I'd like to have this script work.
Thanks for any assistance,
Bill