EpiMan
EpiMan

Reputation: 839

grep: print both matches

the following command returns only matches from file2.

grep -f file1 file2

How is it possible to print match line from the first file (file1) following the second match from file2?

Upvotes: 0

Views: 54

Answers (1)

Ed Morton
Ed Morton

Reputation: 203324

awk 'NR==FNR{res[$0]; next}
{
    found = 0
    for (re in res) {
        if ($0 ~ re) {
            print "found:", re
            found = 1
        }
    }
}
found
' file1 file2

Upvotes: 3

Related Questions