Good day,
I have a list of regular expressions in file1. For each match in file2, print the containing line and the line after.
file1:
file2:
Output:
I can match a regex and print the line and line after
awk '{lines[NR] = $0} /Macrosiphum_rosae/ {print lines [NR]; print lines [NR-1]} '
And I found code online to print lines in file2 based on matches in file1 (untested by me)
awk 'NR==FNR{a[$0]=1;next} {n=0;for(i in a){if($0~i){n=1}}} n' file1 file2
But I'm looking for help in combining the two if anyone would be so kind.
---------- Post updated at 01:50 AM ---------- Previous update was at 12:46 AM ----------
UPDATE:
I was able to solve this.
awk 'NR==FNR{a[$0]=1;next} {n=0;for(i in a){if($0~i){n=1}}} n {print;getline;print}' file1 file2