Try:
while :; do awk '/keyword/{print "found"}'; sleep 1; done < temp.txt
or if you want to execute a shell command instead of just printing "found":
while :; do awk '/keyword/{system("echo \047found\047"}'; sleep 1; done < temp.txt
That uses mandatory POSIX commands and will work in any shell on every Unix box. For example:
$ echo foo > temp.txt
$ while :; do awk '/keyword/{print "\n>>> found <<<\n"}'; sleep 1; done < temp.txt &
[1] 16520
$ echo keyword >> temp.txt
$
>>> found <<<
See https://unix.stackexchange.com/a/629912/133219 for more information on that approach.
If "keyword" doesn't appear often in the file and you care about that loop spinning in the background using CPU cycles, you can get a bit fancier with the sleep value by doubling it up to some max value every time through the loop when keyword isn't found so the code spends far more time sleeping than executing, something like this bash code but can be written for any shell:
secs=1
maxSecs=60
while :; do
if awk '/keyword/{print "found"; f=1} END{exit !f}'; then
secs=1
else
if (( (2*secs) < maxSecs )); then
secs=$(( 2*secs ))
else
secs=$maxSecs
fi
fi
sleep "$secs"
done < temp.txt
That will run awk once per second while "keyword" is showing up that quickly in your file, and when it's not it'll gradually cycle down to calling awk once per minute until "keyword" starts showing up again and then start calling awk once per second again. Obviously set maxSecs to whatever value you like - 5, 30, 3600, whatever.
tail -F file | awk -Winteractive '/keyword/{system("some_command")}'
ortail -F | gawk ...
. – Jan 27 '21 at 01:07