for:
bar1:
key1: value1
bar2:
key2: value2
bar:
foo:
foobar:
key3: value3
How to change value1, value2 and value3 via sed (not yq). In 3 different cases.
CodePudding user response:
It's easier with awk
or perl
$ cat file.yml
for:
bar1:
key1: value1
bar2:
key2: value2
bar:
foo:
foobar:
key3: value3
key4: value4
$ perl -pe 'BEGIN { @new = qw<one two three> } s/^ {4,6}\S : \K. /shift @new/e if @new' file.yml
for:
bar1:
key1: one
bar2:
key2: two
bar:
foo:
foobar:
key3: three
key4: value4
CodePudding user response:
You could just do the obvious thing and use directories.
mkdir -p bar1/key1
echo "hello" > ./bar1/key1/value1
Editing and replacing value1 is extremely easy with that structure.