Введите:
$ cat input
i love potatoes
i love shoes
i love super shoes
i love apple
i love apples
i eat melon
i eat melons
i eat apples and i eat melons
Команда:
awk '{if(NR>1 && length(previous)>0 && index($0,previous)>0){print};previous=$0;}' input
Выход:
i love apples
i eat melons
i eat apples and i eat melons
Пояснения:
{
#skip the first line as by definition there is no line before it
#if the previous line is not empty and if the current line contains the previous line
# (e.g. you can find an index >0 of the previous line string in the current line),
#print the current line
if (NR>1 && length(previous) > 0 && index($0, previous) > 0) {
print $0
}
#assign the current line to previous line and continue the processing
previous = $0
}