Artificial intelligent assistant

Returning only the contents before and after a line number with different matching words I am using cygwin. I have known line# in my hand. Script should look for the first occurrence of the string `mono` above a specified line number and look for the first occurrence of the string `/mono` below the specified line numbers and return only the contents between those `mono` and `/mono`. **Input:** I have known line # in my hand. Script should look for the first occurrence of word mono not monoono above a specified line # and look for the first occurrence of word /mono below the specified line #s and return ONLY the contents between those 'mono' and /mono **Expected Output** mono not monoono above a specified line # and look for the first occurrence of word /mono How can I do this?

Compact version with GNU `sed`:


sed -E 'H;4!d;g;s/.*\/mono/;:a;N;s_/mono\>.*_/mono_;Ta' in


Explanation:

* `H` collects all lines in the hold space
* `4!d` suppresses all output except for 4th line
* At 4th line, move the hold space to the pattern space (`g`) and remove everything upto the word `mono` with the `s` command
* `:a; ... ;Ta` forms a loop appending lines with `N` until `/mono` is read

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 30b81a9502865cddaa669fb4569956b7