I have a yaml file with some missing lines (- source and target under example:) where word1 below needs to be fixed but word2 is ok.
- dyu: word1
alt:
trans:
- lang: fr
detail: null
speech:
- type: null
def:
- gloss: gloss1
note: null
example:
- dyu: word2
alt:
trans:
- lang: fr
detail: null
speech:
- type: null
def:
- gloss: gloss2
note: null
example:
- source: some example source
target: some example target
- dyu: word3
I have used the following to insert the missing text:
awk -i inplace -v data=" - source:\n target:" '/example:/ {f=1} /- dyu:/ && f {print data; f=0}1' $file
But the problem is it will also insert the text even where it exists. I need to add the missing text exactly between example:\n - dyu, and not between target: something\n -dyu.
Desired output:
- dyu: word1
alt:
trans:
- lang: fr
detail: null
speech:
- type: null
def:
- gloss: gloss1
note: null
example:
- source:
target:
- dyu: word2
alt:
trans:
- lang: fr
detail: null
speech:
- type: null
def:
- gloss: gloss2
note: null
example:
- source: some example source
target: some example target
- dyu: word3
How can I achieve this?