Perl /Sed replacement

perlsed

Below command is used to replace the password in a script but the perl command is adding a white space when it does the subsstitution

password=arche20
perl -i -p -e "s/^(password[]*=[ ]*).*$/\1 $passwd/" config.properties

cat config.properties
userid=ARCHE
password= arche20

It does the work but it seems to be adding a space after password when it replaces.
Could this be done without the space?
Got a sed way:

sed -i "s/password.*/password=$passwd/g"

Best Answer

You have a space after \1 in your replacement, just remove that and you should be good

perl -i -p -e "s/^(password[]*=[ ]*).*$/\1$passwd/" config.properties
                                          ^
                                          Removed space here
Related Question