我想知道如何写一个AWK代码:
\n_ _ _
取代;_
(每个_
是一个空格)到目前为止,我所做的是:
awk -vRS="\n " -vORS="; " '1' '/^C1 / {print $0}' file
输入:
AU Luna, J
Plata, M
C1 [Luna, Joaquin; Gonzalez, Mauricio] Inst Nacl Cancerol, Bogota, Colombia.
[Plata, Manuel] Fdn Cardioinfantil, Bogota, Colombia.
输出:
C1 [Luna, Joaquin; Gonzalez, Mauricio] Inst Nacl Cancerol, Bogota, Colombia.; [Plata, Manuel] Fdn Cardioinfantil, Bogota, Colombia.
答案 0 :(得分:1)
说你的文件是:
aaa
bbb
ccc
ddd
你想要一个awk命令:
aaa
替换为bbb
[bc]
这样的事情可行:
gawk '{ gsub(/aaa/, "bbb") } /[bc]/ { print }' file
答案 1 :(得分:1)
$ awk 'sub(/^ +/,"; "){if (p ~ /^C1/) print p $0} {p=$0}' file
C1 [Luna, Joaquin; Gonzalez, Mauricio] Inst Nacl Cancerol, Bogota, Colombia.; [Plata, Manuel] Fdn Cardioinfantil, Bogota, Colombia.