Louis I. answered 08/15/20
Computer Science Instructor/Tutor: Real World and Academia Experienced
So here's a notional script that matches your description:
ANGLE1 = 40
ANGLE2 = 50
GO TO 100 ## ANGLE2=256
IF X = 512 ...
## end of script
Let's use ANGLE2 as my example variable we're hunting for.
So I want the 2nd line above, but not the 3rd.
Maybe I'm missing something, but doesn't this do what you're looking for?
$ grep -in -e "angle2" script | grep -vi "#.*angle2"
2:ANGLE2 = 50
It does mean using a 2nd grep process, and avoiding that would be nice if you could ...
I was wondering if egrep can be used to avoid the pipline ...
The following would grab lines that match either ANGLE1 or ANGLE2
$ egrep -ni -e "ANGLE1" -e "ANGLE2" script
1:ANGLE1 = 40
2:ANGLE2 = 50
3:GO TO 100 ## ANGLE2=256
But can we ask egrep to match pattern1, except if pattern2 is in the mix?
Is there a regular-expression that would accomplish that?
I haven't found one yet, but will follow up here if I do