-2

i have a config file with this format

http://link:port/username/password/1234

Im using this code to replace the Username1/Password1 with a different Username2/Password2

sed -i -e 's/\/Username1\/Password1/\/Username2\/Password2/g' /etc/config.cfg

Now i want to make this something like

$UsernameOLD = Username1
$PasswordOLD = Password1

$UsernameNEW = Username2
$PasswordNEW = Password2

sed -i -e 's/\/$UsernameOLD\/$PasswordOLD/\/$UsernameNEW\/$PasswordNEW/g' /etc/config.cfg

Could anyone help me getting this ready ?

Juggybash
  • 25
  • 6

1 Answers1

0

I found the solution i had to use double quotes instead of '

The working command looks like this:

UsernameOLD=MyOldUsername
PasswordOLD=MyOldPassword
UsernameNEW=MyNewUsername
PasswordNEW=MyOldUsername

sed -i -e "s/\/$UsernameOLD\/$PasswordOLD/\/$UsernameNEW\/$PasswordNEW/" /etc/config.cfg
Juggybash
  • 25
  • 6