Dav*_*rks 1 linux bash awk text
我有一个看起来像这样的文件:
ignoretext
START
a b
c d
e
END
ignoretext
START
f g h
i
END
ignoretext
Run Code Online (Sandbox Code Playgroud)
我想把它翻译成以下几行:
a b c d e
f g h i
Run Code Online (Sandbox Code Playgroud)
这是一种方法 awk
awk '/END/ {ORS=RS;print "";f=0} f; /START/ {ORS=" ";f=1}' file
a b c d e
f g h i
Run Code Online (Sandbox Code Playgroud)
添加了一个在行尾不提供空间的版本.这可能是更短的方式
awk 'a && !/END/ {printf FS} /END/ {print "";f=a=0} f {printf "%s",$0;a++} /START/ {f=1}'
a b c d e
f g h i
Run Code Online (Sandbox Code Playgroud)