Artificial intelligent assistant

Printing end match only if there was a beginning match I have the following `awk` file. The problem is that when there is a match for `$0 ~ end_ere` the line gets printed. But what I want is that the line is printed only when there was previously a match for `$0 ~ beg_ere`. What can I do? `beg_ere` matches the beginning of a section, whereas `end_ere` matches the end of a section. `pn_ere` removes the comment characters at the beginning of the line. If `showpr` is true, the lines matching `beg_ere` and `end_ere` are printed. Otherwise, only the lines within the section lines are printed (meaning that the lines matching `beg_ere` and `end_ere` are not printed). $0 ~ beg_ere { display = 1 if ( ! showpr ) { next } } $0 ~ end_ere { if (( display == 1 )); then if ( ! showpr ) { print "" } else { sub(pn_ere, "") ; print ; print "" } fi display = 0 } display { sub(pn_ere, "") ; print }

From your description it sounds like this is what you're trying to do:


$0 ~ beg_ere {
inBlock = 1
}

inBlock {
lines[++numLines] = $0
if ( $0 ~ end_ere ) {
delta = ( showpwr ? 0 : 1 )
for ( lineNr=(1+delta); lineNr<=(numLines-delta); lineNr++ ) {
sub(pn_ere, "", lines[lineNr])
print lines[lineNr]
}
inBlock = numLines = 0
}
}


but obviously I couldn't test it as you didn't provide any sample input/output in your question and the code in your question isn't a minimal, complete script that could be executed.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 68b89e9ba0f2eec7151849744da8d4cc