I have 2 text files. file1 contains a list of IDs:
11002
10995
48981
79600
file2:
10993 item 0
11002 item 6
10995 item 7
79600 item 7
439481 item 5
272557 item 7
224325 item 7
84156 item 6
572546 item 7
693661 item 7
.....
I am trying to select all lines from file2 where the ID (first column) is in file1. Currently, what I am doing is to loop through the first file to create a regex like:
^\b11002\b\|^\b10995\b\|^\b48981\b|^\b79600\b
Then run:
grep '^11002\|^10995\|^48981|^79600' file2.txt
But when the number of IDs in file1 is too large (~2000), the regular expression becomes quite long and grep becomes slow. Is there another way? I am using Perl + Awk + Unix.