user3214998
user3214998

Reputation:

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? How can this be done?

(the mark line should never be printed out)

Upvotes: 0

Views: 161

Answers (2)

Ed Morton
Ed Morton

Reputation: 203229

$ awk '/mark/{f=!f;next} !f' file
aeht
yeaja

Upvotes: 3

Kent
Kent

Reputation: 195039

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

Upvotes: 3

Related Questions