Using sed to Find first string, then next string

I know that if file is
now
is
the
time
for
all
good
men
house
boat
car
for

sed -n -e '/is/,/for/p' file

will print
is
the
time
for

But how do I get, for instance ONLY
the line "is"
and the next occurrence of "for"

Search for "is", if I find "is", search for and print "is" and the first occurrence of "for"

Whats the expected output?
is
for
?

Yes.

is
for (only the first occurrence following is )

simple would be..

 
 sed -ne '/is/p' -e '/for/{p;q}' filename
1 Like