Skip to content
Advertisement

How to put a value after certain pattern in a Linux file

I run a script which stores a value in a variable like this:

secret=`aws secretsmanager get-secret-value --secret-id <secretid> --region eu-west-1|grep SecretString|awk -F" '{print $4}'`

Now I have a file called env-list which has an entry like this:

secret=

I want to redirect the output of first command to paste after = sign in env-list file, so that my env-file holds the secret value from first command: secret=value.

I am struggling a lot with this.

Advertisement

Answer

sed -i "s/^secret=.*/secret=$secret/g" env-list
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement