Grabbing Keywords Below a Searched Keyword

Hello,
I have a text file like the one found below and wouild like the grab the certain lines after the searched phrase. For example, I'd like to look up "Hello" and once I find the "Hello" section, grab the lines that contain "Text" and stops at the next section.

Input.txt

Example Hello
Filler A
Filler B
Filler C
Text Bon Jour
Text Salut
Text Hola
Filler Z
Example Bye
Filler A1
....
...
 

desired output:

Text Bon Jour
Text Salut
Text Hola

What's your system?

I'm running on an AIX machine.

sed -n '/Example Hello/,/Example/s/Text.*/&/p' myFile
1 Like

wow, didn't realize sed can be used like that! thanks!

---------- Post updated at 02:43 PM ---------- Previous update was at 02:43 PM ----------

what would the sed syntax look like if I wanted to reverse the order?

So if I was looking for "Text Bon Jour" my ouput would be "Example Hello"?

Please provide a representative data sample and a desired output.

well, I guess the input file would be the same:

Example Hello
Filler A
Filler B
Filler C
Text Bon Jour
Text Salut
Text Hola
Filler Z
Example Bye
Filler A1
....
...

and if I did a query for "Text Bon Jour" or "Text Hola", my ouput would be the following:

Example Hello
nawk -v p='Text Bon Jour' '/^Example/{e=$0;next} $0~p{print e}' myFile

can this be modified so that if the p value is not found, then it will just echo out the p value.

For example, query for "Wow" will echo out wow since it's not in the input file. A querey for "Text Bon Jour" will echo "Example Hello"