Obtain patterns in one file from another using ack or awk or better way than grep?

Posted by Rock on Stack Overflow See other posts from Stack Overflow or by Rock
Published on 2012-03-30T04:18:08Z Indexed on 2012/03/30 5:30 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

Is there a way to obtain patterns in one file (a list of patterns) from another file using ack as the -f option in grep? I see there is an -f option in ack but it's different with the -f in grep.

Perhaps an example will give you a better idea. Suppose I have file1:

file1:
a
c
e

And file2:

file2:
a  1
b  2
c  3
d  4
e  5

And I want to obtain all the patterns in file1 from file2 to give:

a  1
c  3
e  5

Can ack do this? Otherwise, is there a better way to handle the job (such like awk or using hash) because I have millions of records in both files and really need an efficient way to complete? Thanks!

© Stack Overflow or respective owner

Related posts about regex

Related posts about perl