我有这样的文字
replace: c
1: USA
-
replace: SN
1: Garlapati
对于以replace:
开头的每一行,我想使用以下单词替换下一行的第一个单词(在这种情况下为1
):
replace: c
c: USA
-
replace: SN
SN: Garlapati
答案 0 :(得分:0)
这一行应该:
awk -F': *' -v OFS=": " '$1=="replace"{r=$2;print;next}r{$1=r;r=""}7' file
测试你的输入:
kent$ cat f
replace: c
1: USA
-
replace: SN
1: Garlapati
kent$ awk -F': *' -v OFS=": " '$1=="replace"{r=$2;print;next}r{$1=r;r=""}7' f
replace: c
c: USA
-
replace: SN
SN: Garlapati