Q:

grep: printing different patterns on different lines

Here is a sample list:
apple
pear
orange
orange
apple
orange
pear
orange
pear
orange
apple

What I am trying to achieve is to print a full orange line only if the line after (below) has apple in it (and this line will also be printed). Using the list above, grep would return the lines marked by a hyphen:
apple
pear
orange
-orange
-apple
orange
pear
orange
pear
-orange
-apple

Here is my best attempt so far, I start the command with strings:
strings fruits.txt | egrep 'orange' -A 1 'apple'

But it returns "grep: apple: No such file or directory".
Any help would be appreciated!

A:

Interesting challenge. I think that sed would be a better tool for that job.
sed '/orange/ N; /orange.*\n.*apple/ !{D; N;};' fruits.txt

