[英]AWK command print inversion
there is some help needed to what comes in... let's say we have the following text into a file 进来的东西需要一些帮助...假设我们将以下文本放入文件中
aeht
mark
tjae
aejra
ytha
mark
yeaja
so it's gotta start printing until it finds the word mark
, which will not print but change the behaviour of awk and stop printing the next lines until it spots the second mark
with which it will start printing again and so on everytime it spots a mark
the behaviour will change... Is it possible? 所以它必须开始打印,直到找到单词mark
为止,该单词不会打印,但会更改awk的行为,并停止打印下一行,直到发现第二个mark
,然后再次开始打印,依此类推,直到每次发现一个mark
行为将会改变...可能吗? How can this be done? 如何才能做到这一点?
(the mark
line should never be printed out) ( mark
线永远不要打印出来)
No matter if you want the "mark" in your output or not, this line should give you help: 无论您是否要在输出中使用“标记”,此行都应为您提供帮助:
awk -v f=1 '/^mark$/{f*=-1;next}f>0' file
test: 测试:
kent$ cat file
1
2
mark
3
4
5
mark
6
7
8
mark
9
10
kent$ awk -v f=1 '/^mark$/{f*=-1;next}f>0' file
1
2
6
7
8
$ awk '/mark/{f=!f;next} !f' file
aeht
yeaja
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.