I am creating a backup web server but I want the backup server to only have one root user. So after moving all the databases I need to replace all the mysqli_connect(...)
lines in db.txt
.
I have written:
beg="mysqli_connect("
end=");"
#need to find out the database
db="123"
new="'localhost','root','pass','$db'"
cat db.txt | sed "s/$beg.*$end/$beg$new$end/"
to replace all the configs, but I need to find out the database. I can do this by getting the text between the $end
and the previous ',
' but how would I go about getting that with sed?
input:
Potential file:
sadnkjnadsjknfaskdjfnlasdnfkdsa
safdjnasdkjjfasndka
asfdknjdsakjfnasjdnkfsadnjkads mysqli_connect("192.168.1.10","dave","password","DavesDB");
sdfnjnweewrewqrfgjdgnf
vncnccnvxjncvjn4wrwerewrewerwjvcnxjnvcj
mysqli_connect("192.168.1.10" , "tom" , "password" , 'TomsDB'); dsanjasdknfjansd
sakfdnjsadjkfnsa
sknfdsjdnfjsdnnqwerweq
output:
sadnkjnadsjknfaskdjfnlasdnfkdsa
safdjnasdkjjfasndka
asfdknjdsakjfnasjdnkfsadnjkads mysqli_connect("localhost","root","rootpassword","DavesDB");
sdfnjnweewrewqrfgjdgnf
vncnccnvxjncvjn4wrwerewrewerwjvcnxjnvcj
mysqli_connect("localhost","root","rootpassword","TomsDB"); dsanjasdknfjansd
sakfdnjsadjkfnsa
sknfdsjdnfjsdnnqwerweq