How to feed awk input from both pipe and file?

后端 未结 1 935
说谎
说谎 2021-01-19 01:32

I was wondering how do I get awk to take a string from the pipe output and a file?

I\'ve basically have a chain of commands that eventually will spit out a string.

相关标签:
1条回答
  • 2021-01-19 01:48

    As Karoly suggests,

    str=$( rest of commands that will give a string )
    awk -v s="$str" -F, '$7==s {print $5; exit}' file
    

    If you want to feed awk with a pipe:

    cmds | awk -F, 'NR==FNR {str=$0; next}; $7==str {print $5}' - file
    

    I think the first option is more readable.

    0 讨论(0)
提交回复
热议问题