ifconfig | grep ^en1 -A5 | grep inet | head -n 1
This is just for the sake of an example of finding $foo that occurs after $bar. Substitute ifconfig and the arguments of grep appropriately for your use case.
ifconfig there are several lines with inet. We want to get to the first one that comes after a line starting with en1grep ^en1 -A5 will print the line starting with en1 and the next 5 lines that follow itgrep inet will print only the lines matching inethead -n 1 will print only the first lineThe value 5 in -A5 is really just a guess that the line we're interested in will be within the next 5 lines, the appropriate number depends on your use case.
Kind of a dumb technique, but it's easy to remember.