I have a yaml file like this:
spec:
values:
image: xxxx.dkr.ecr.eu-west-1.amazonaws.com/xxxx:mypr-ij4uhtuh3
I’m finding adding this this text: # {"$imagepolicy": "xxx:xxx-test-pr333" } at the end of the line containing the word image surprisingly hard.
I’ve tried with sed, awk and ruby but I can’t get it straight, sed is especially confusing with all those special characters and spaces.
the end result should be this:
spec:
values:
image: xxxx.dkr.ecr.eu-west-1.amazonaws.com/xxxx:mypr-ij4uhtuh3 # {"$imagepolicy": "xxx:xxx-test-pr333" }
thanks for any hint.
>Solution :
This might work for you (GNU sed):
sed 's/^\s*image:.*/& # {"$imagepolicy": "xxx:xxx-test-pr333" }/' file
Match a line that following some whitespace begins image: and append # {"$imagepolicy": "xxx:xxx-test-pr333" }/ to it.