2

I can't seem to find an answer, I am trying to find and replace a text.

For example, find newName: and replace it with a variable that expands.
I tried:

sed -i "/  newTag:/c  newTag: $IMAGE_TAG"

This one removes indentation and adds double quotes to the value (which I don't want). I only want 2 indentations before the key NewName, and it's value, like NewName: newvalue

This below is a YAML format of a list of images:

images:
    name: alpine/docker
    newName: replaceme
    newTag: replaceme
davide-pi
  • 182
  • 6
Turgut
  • 21
  • 1
  • 3

1 Answers1

0

The s or substitute command of sed can replace a value in a line and leave everything else intact. It can also expand Bash variables in the substitution.

newtag="NEWTAG"
echo "    oldTag: value" | sed  "s/oldTag:/$newtag:/"

outputs:

    NEWTAG: value

More on s on the SED Manual.