Skip to content

Instantly share code, notes, and snippets.

@tanmay-bhat
Created May 21, 2022 12:37
Show Gist options
  • Save tanmay-bhat/fb70f7112e0cd79eef492cebb0a8bfad to your computer and use it in GitHub Desktop.
Save tanmay-bhat/fb70f7112e0cd79eef492cebb0a8bfad to your computer and use it in GitHub Desktop.
Use sed to replace value of key-value pair
sed -i '/^old-value /s/=.*$/=new-value/' file-name

Example

cat terraform.tfvars.example project_id = "gcp-123"

sed -i '/^project_id /s/=.*$/=gcp-456/' terraform.tfvars.example

replaces gcp-123 with gcp-456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment