I have a file which contain following lines
app.mail.host = 10.1.1.1
app.mail.debug = true
app.db.username = spate
app.db.password = 1#4FnL&@7!
I want to use regex to change actual password and replace with XXXXXXX for security purpose.
I am trying following regex but it doesn’t working.
sed 's/app\.db\.password="[^"]\+/app\.db\.password="XXXXXXXX"/g' foo.txt
As Hbcdev noted, you aren’t matching due to whitespace. As this appears to be “security” code (in which case — why are you storing that password in plaintext at all?), it’s probably better to be whitespace-tolerant than match the input byte-for-byte. Something like:
(untested) is probably going to work a little more robustly. Note that it will strip your password field even if it doesn’t begin with a quote.
Still, doing this kind of hackery with a shell script sounds dangerous. What are you trying to accomplish?