I am trying to use grep to extract the matching words from file1 in file2 and directing to output file.
I have file1
Acetoanaerobium sticklandii
Acetobacter pasteurianus
like >1000 species.
File2
>WP_013360383.1 ATP-dependent Clp protease ATP-binding subunit [Acetoanaerobium sticklandii]
>WP_013360396.1 ATP-dependent Clp protease ATP-binding subunit [Acetoanaerobium sticklandii]
>WP_003623694.1 multidrug efflux RND transporter permease subunit [Acetobacter pasteurianus]
>WP_003624003.1 superoxide dismutase [Acetobacter pasteurianus]
>WP_003624029.1 UDP-galactopyranose mutase [Acetobacter pasteurianus]
>WP_003624540.1 mannose-1-phosphate guanylyltransferase/mannose-6-phosphate isomerase [Acetobacter pasteurianus]
>WP_077905956.1 effector protein [Salmonella enterica]
>WP_077905962.1 type III secretion system YopJ family effector AvrA [Salmonella enterica]
>WP_005544680.1 3-deoxy-8-phosphooctulonate synthase [Aggregatibacter actinomycetemcomitans]
>WP_005545812.1 MFS transporter [Aggregatibacter actinomycetemcomitans]
>WP_005546163.1 UTP--glucose-1-phosphate uridylyltransferase GalU [Aggregatibacter actinomycetemcomitans]
and so on..
when I am using the code
grep -f file1 file2 > output
or
fgrep -f file1 file2 > output
The resulting output is the list containing the last line of file1 and remaining input list is ignoring by grep. Even with -w option also the output is same.
Why the grep is behaving like this? Is it problem with my shell? I am using MacBook with Mojave OS version.
Please suggest me equivalent awk commands.
I tried
awk 'NR==FNR{a[$0];next}$NF in a{print}' file1 file2 > output
but resulted empty file.