I have a log file and I need to extract the sections related to a specific event. I performed something similar before but easier with the "sed" command.
The task I've been trying to solve is the following. I need to extract all the portions of text in the file starting with the word "BEGIN" included and ending before the next "BEGIN" where it is included a specific word identifying a table in my database. I need help with the usage of the sed command.
The task can be summarized in "search between all occurrences delimited by Start and End containing the word word"
The text looks like something like this:
BEGIN
...
something here
something here containing the desired "word"
something here
...
COMMIT
BEGIN
.
.
.
COMMIT
BEGIN
And I want to obtain all the occurrencies conaining "word" as this:
BEGIN
...
something here containing the desired "word"
...
COMMIT
awk
to a) select text blocks between START and END keywords and b) only prints the block if the MATCH keyword is found. – FelixJN Dec 28 '20 at 15:35BEGIN
andCOMMIT
lines will always be separate lines as shown in the example. Can there be more than one line betweenBEGIN
andCOMMIT
? Please [edit] your question to add requested information, don't use comments to answer. Additional requirements should also be added to the question. – Bodo Dec 28 '20 at 15:37awk 'BEGIN{RS="BEGIN"} /word/' inputfile
orawk 'BEGIN{RS="(\n*COMMIT)?\n*BEGIN\n*"} /word/' inputfile
orawk 'BEGIN{RS="(COMMIT\n*)?BEGIN\n*"} /word/' inputfile
? – Bodo Dec 28 '20 at 15:50