Issue
I try to figure out, how to use sed to get the lines between to patterns (in my case parts of html tags) without printing the second pattern. The problem occurs if having 2+ matches.
I try to explain with a example: File:
...
Keyword #1
animal
rainbow
train
Keyword #2
...
Keyword #1
female
lawyer
monkey
rainbow
Keyword #2
My expected result:
Keyword #1
animal
rainbow
train
Keyword #1
female
lawyer
monkey
rainbow
So is it possible to ignore every "last pattern" after match?
Second Example:
I am using the opening pattern for finding the next keyword. But its also at the statement with Keyword#1...
<p href=... Keyword#1 ....
Keyword#2 is "<p"
I am using the
<p TAG
to define the last pattern
Solution
This awk
may do:
awk '/Keyword #1/ {f=1} /Keyword #2/ {f=0} f' file
Keyword #1
animal
rainbow
train
Keyword #1
female
lawyer
monkey
rainbow
It will use a start keyword and a stop keyword.
Answered By - Jotne