Beno Odr
Beno Odr

Reputation: 1273

override file property with script

I want to change a value inside yaml file

e.g. yaml

...
metadata:
  name: appname
spec:
  replicas: 3
  selector:
    matchLabels:
      app: %APP_NAME%

Now I tried with the following

sed -i 's/%APP_NAME%/newappname/g' app.yaml

And I got error:

sed: 1: "app.yaml": extra characters at the end of d command

Im not sure how to overcome this, what I need it to override the file value and not just to see it as output

at the end the file should look like

...
metadata:
  name: appname
spec:
  replicas: 3
  selector:
    matchLabels:
      app: newappname

If I remove the -i from the command I was able to see the output as requested however I need to override the file value and not just to see the output

Upvotes: 1

Views: 315

Answers (1)

rid
rid

Reputation: 63540

Some versions of sed require the argument to -i, while on others it's optional.

Try:

sed -i .bak 's/%APP_NAME%/newappname/g' app.yaml

or sed -i '' ... if you don't want to create any backup (not recommended, see the sed manual about this).

Upvotes: 2

Related Questions