Calling Awk in a shell script

后端 未结 4 1654
遥遥无期
遥遥无期 2021-01-18 19:32

I have this command which executes correctly if run directly on the terminal.

awk \'/word/ {print NR}\' file.txt | head -n 1

The purpose i

4条回答
  •  鱼传尺愫
    2021-01-18 19:34

    you could also pass the value as a variable to awk:

    awk -v varA=$1 '{if(match($0,varA)>0){print NR;}}' $2 | head -n 1
    

    Seems more cumbersome than the above, but illustrates passing vars.

提交回复
热议问题