I'm currently working with a text file that contains the following text blocks:--------------------------------------Beginning of blockTextRandom TextkeywordATextEnd of block----------------------------------------------------------------------------Beginning of blockTextRandom TextkeywordATextEnd of block----------------------------------------------------------------------------Beginning of blockTextRandom TextkeywordDTextEnd of block----------------------------------------------------------------------------Beginning of blockTextRandom TextkeyworddTextEnd of block--------------------------------------The objective is to have egrep detect certain keywords, and if those words exist, I would like to copy the block to another file. So, I'm currently searching with:if egrep -wi 'keywordA|KeywordB|keywordC' Reportthen        echo Words found!else        echo No words found!fiI was wondering if there is any way to add a follow up action to use sed (for example) to copy the block of text where the words were found.Expected output, in this example, would be:--------------------------------------Beginning of blockTextRandom TextkeywordATextEnd of block----------------------------------------------------------------------------Beginning of blockTextRandom TextkeywordATextEnd of block--------------------------------------The file Report contains dozens of blocks like this, but not all of them have the keyword. I would like to copy just the ones that do (as demonstrated in the above example).I hope this makes sense!Thank you in advance for any help or pointers!
Extracting text blocks based on grep output
text processing;awk;sed;grep;scripting