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
You should use AWK's variable passing feature:
awk -v patt="$1" '$0 ~ patt {print NR; exit}' "$2"
The exit makes the head -1 unnecessary.
exit
head -1