I have a file:
$ cat test.csv
hello foo
needed
bar
blah
blah
bar
hello foo
needed
bar
blah
hello foo
needed
hello foo
needed
bar
blah
I need to extract lines having 'bar' and immediate line next to 'hello' but not the 'hello' line. So far i am able to extract as below but not able to ignore 'hello' lines. I can try extracting with another awk, but wonderign if there a oneliner that can take care of it in one go?
$ awk '/hello|bar/;/hello/{getline;print}' test.csv
hello foo
needed
bar
bar
hello foo
needed
bar
hello foo
needed
hello foo
needed
bar
EDIT: expected output-
needed
bar
bar
needed
bar
needed
needed
bar