使用\ hello跳过以\ hello开头的一行
awk '/\\hello/{next}'
如何编辑上面的命令以跳过\ hello和\ hello2之间的行?
输入
text
\hello
text
hi
\hello2
text2
所需的输出:
text
text2
使用\ hello跳过以\ hello开头的一行
awk '/\\hello/{next}'
如何编辑上面的命令以跳过\ hello和\ hello2之间的行?
输入
text
\hello
text
hi
\hello2
text2
所需的输出:
text
text2
在其not recommended way中,您可以执行以下操作:
$ awk '/^\\hello$/,/^\\hello2$/{next}1' file
更好,更适应的方式是:
$ awk '/^\\hello$/{f=1}(f==0){print};/^\\hello2$/{f=0}' file
这也是可还原的:
$ awk '/^\\hello$/{f=1}!f;/^\\hello2$/{f=0}' file
或查看埃德·莫顿(Ed Morton)的评论(见下文)