【发布时间】:2022-01-16 04:39:09
【问题描述】:
我有一个 yaml 文件,其中缺少一些行(示例下的源和目标:),其中下面的 word1 需要修复,但 word2 没问题。
- 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
我已使用以下内容插入缺失的文本:
awk -i inplace -v data=" - source:\n target:" '/example:/ {f=1} /- dyu:/ && f {print data; f=0}1' $file
但问题是即使文本存在,它也会插入文本。我需要在example:\n - dyu 之间添加缺少的文本完全,而不是在target: something\n -dyu. 之间添加
期望的输出:
- 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
我怎样才能做到这一点?
【问题讨论】:
标签: awk