1

I need to update values on the .yml file

For example, On below I need to modify only the version

name: dummyaml
description: >-
  blah blah blah.

version: 1.2.3

environment:
  sdk: '>=2.10.0 <3.0.0'
  
dependencies:
  efts: ^2.0.4
  transmogrify: ^0.4.0
  
dev_dependencies:
  test: '>=1.15.0 <2.0.0'

I tried this

sed -i 's/^version:.*/version:'"$VERSION"'/' xy.yaml got below error

sed: 1: "xy.yaml": extra characters at the end of x command

3
  • 1
    Kindly do add your tried code as your efforts in your question, which is highly encouraged on SO, thank you. Commented Aug 3, 2022 at 19:55
  • 1
    while in your case you can do it with sed or awk, you should use yq for manipulating YAML from the shell Commented Aug 3, 2022 at 19:59
  • This might help: yq e '.version |= "1.2.4"' <file.yaml Commented Aug 3, 2022 at 21:05

1 Answer 1

4
sed 's/^\(version: \).*$/\15.6.7/' input.yml
  • sed 's/PATTERN/REPLACEMENT/': PATTERN matches something from the source. REPLACEMENT is what you now want to appear in the modified content.
  • \1: is the content of the text in parentheses in the PATTERN. Here, version:
  • ^: starts with
  • $: ends with
  • 5.6.7: some version I put there, put your own desired value

IMPORTANT: this will only work if you only have version: SOMETHING in the file. If you have more than one version: line, it will modify both!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks sed 's/^\(version: \).*$/\1'"$VERSION"'/' xy.yaml works for me

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.