How to grep only if pattern1 and pattern2 matches in consecutive lines
grep
Solution
You can do it with pipes - `grep -A1 city <filename> | grep -B1 "bad food"` or `cat filename | grep -A1 city | grep -B1 "bad food"` (or any other stream source for the pipe)
Problem
I have a file like below: ``` city-italy good food bad climate - city-india bad food normal climate - city-brussel normal dressing stylish cookings good food - ``` Question - I want to grep `city` and `food`, for which "food" is "bad". For example - for the above question, i need a grep command to get a answer like below ``` city-india bad food ``` Please help me like, how i will get pattern 1 and pattern 2 grepped only if both succeeds parallely. i mean both pattern should match and it should grep in the following line.