Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

add text at the end of specific line

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading