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? How can this be done?
(the mark
line should never be printed out)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.