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

后端 未结 5 1577
不知归路
不知归路 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 07:58

    You can convert the file into a regex for ack with tr. I used sed to remove the trailing pipe character.

    ack "`tr '\n' '|' < patts | sed 's/.$//'`"

    Note you need a couple of processes for this so the awk solution is probably more efficient, but this is quite easy to remember.

提交回复
热议问题