I know grep -C -A -B commands – but I have file that I cannot use any of these options on –
I need to find a pattern/match lets say XYZ once I find the XYZ i need to find first occurrence on YYY above it and assign that to a variable . In example below I want to find the “JELLY” assign it to $VAR1 and then look for the first line that has REC in it and in this case assign the value fish2 to $VAR2 — This is a huge file and each section length starting with REC is different in number line it contains ? Please assist .
Example:
</REC> this is very "fish1">
</ test a >
</ test b >
</ test c " WHITE" />
</ test w >
</ test x >
</ test y >
</ test z >
</REC> this is very "fish2">
</ test d >
</ test e >
</ test f "JELLY" />
</ test d >
</ test e >
</REC> this is very "fish3">
</ test o "RED" />
</ test p >
</ test q >