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
Replace the single quotes with double quotes so that the $1 is evaluated by the shell:
$1
awk "/$1/ {print NR}" $2 | head -n 1