Parsing Multiple Lines of stdout in Bash

Hello all,

I am trying to pipe an output to something like sed or awk to parse it based on my delimiter. However, I am struggling with the fact that sed reads line-by-line - so, my use of Regex is not effective.

Input

Some text I do not want
--fcc--
The text I do care about
--fcc--
Some more text I do not want

Output

The text I do care about

Note: I want to preserve spaces and tabs, and what-have-you within the delimiter bounds.

What I thought would work:

sed -E 's/[\s\S]+--fcc--([\s\S]+?)--fcc--[\s\S]+/\1/'

I have read through most of sed's manual, and tried to make the Text search across multiple lines work, but do not understand it well enough I guess :man_shrugging:

Something to play with: https://replit.com/@Sky020/stdout-parsing#main.sh

Any help is appreciated

1 Like

Sometimes, I feel like I use this forum as my debugger duck :duck:

The solution came from following this: https://www.baeldung.com/linux/print-lines-between-two-patterns

Nothing more than:

sed -n '/--fcc--/, /--fcc--/{ /--fcc--/! p }'
1 Like