How to run grep inside awk?

后端 未结 6 2142
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 11:22

Suppose I have a file input.txt with few columns and few rows, the first column is the key, and a directory dir with files which contain some of these

6条回答
  •  离开以前
    2021-02-15 11:46

    grep requires parameters in order: [what to search] [where to search]. You need to merge keys received from awk and pass them to grep using the \| regexp operator. For example:

    arturcz@szczaw:/tmp/s$ cat words.txt 
    foo
    bar
    fubar
    foobaz
    arturcz@szczaw:/tmp/s$ grep 'foo\|baz' words.txt 
    foo
    foobaz
    

    Finally, you will finish with:

    grep `commands|to|prepare|a|keywords|list` directory
    

提交回复
热议问题