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

后端 未结 5 1585
不知归路
不知归路 2020-12-06 07:16

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 i

5条回答
  •  广开言路
    2020-12-06 08:01

    nawk 'FNR==NR{a[$0];next}($1 in a)' file3 file4
    

    tested:

    pearl.384> cat file3
    a
    c
    e
    pearl.385> cat file4
    a  1 
    b  2 
    c  3 
    d  4 
    e  5
    pearl.386> nawk 'FNR==NR{a[$0];next}($1 in a)' file3 file4
    a  1 
    c  3 
    e  5
    pearl.387>
    

提交回复
热议问题