I have a simple grep command that returns lines that match from a file. Here's the problem: Sometimes, when a line matches, I want to include the line before it. What I want is a way to find all the lines that match a pattern, then use a different pattern to see if the line before each of those results match.
Let's say I want to get all lines containing 'bar', and the line before each of those only if they contain 'foo'. Given an input like this:
Spam spam eggs eggs Let's all go to the bar. Blah Blah Blah foo. Meh. foo foo foo Yippie, a bar.
I'd like a result like this:
Let's all go to the bar foo foo foo Yippie, a bar.