Calling Awk in a shell script

后端 未结 4 1666
遥遥无期
遥遥无期 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:58

    Replace the single quotes with double quotes so that the $1 is evaluated by the shell:

    awk "/$1/ {print NR}" $2 | head -n 1
    

提交回复
热议问题