in reply to help: extracting multiple lines from file based on match in one line

Now that your basic problem is solved, I'm wondering: whose idea was it to invent this file format, and why was it made to be just sort of like -- but significantly different from -- XML?

If the tagging for the data structure went like this, it would qualify as valid XML:

<rec id=4> varFoo = bar some text some text ... </rec>
Not only would you have the option of using some very handy and powerful XML modules and tools on the data, but you would also find it easy to do "one-liner" stuff using the constant-string close tag as the input record separator -- e.g.:
# command line perl script to put all "var2 = 3" chunks into a separat +e file: perl -ne 'BEGIN{ $/="</rec>\n" } print if /var2 = 3/' input > var2_3.o +utput # just do the opposite (change "if" to "unless") to save the other chu +nks elsewhere
As it is, with a space in every close tag, and all close tags being different, your data is not XML, and it's a pain in the neck.