Hi,
I know how to replace a string with another in a file.
But, i wish to replace the below string pattern
EncryptedPassword="{gafgfa}]\asffafsf312a"
i.e EncryptedPassword="<any random string>"
To
EncryptedPassword=""
i.e remove the random password to a empty string.
Can you please let me know how can I achieve this ?
This is a job for sed
sed -e 's/EncryptedPassword="[^"]*"/EncryptedPassword=""/'
1 Like
Or with a back-reference; for example if you allow spaces around the =
it will keep them.
sed 's/\(EncryptedPassword *= *\)"[^"]*"/\1""/'
In contrast to .*
the [^"]*
does a minimum match; important in case more "strings" follow it.
perl -pe
is quite similar to sed (and even to awk); a minimum match can be elegantly done by a ?
after a "greedy" *
:
perl -pe 's/(EncryptedPassword *= *)".*?"/$1""/'