In bash, I have a command running in screen that is effectively:
while true
do
echo $RANDOM
sleep 1
done
The output of which is:
12396
19683
31641
...
I'd like to pipe that into something like grep/awk and I match a specific pattern, such as 12345
, I want a command to run.
I don't want to capture the full output of the running command - it may run for a very long time before a match is found and I don't want to waste space on the machine.
Can this be done easily in bash?
In an ideal world, I would also like the output the continue to be printed to the terminal, so I can remote in and monitor the output myself, but that's not strictly necessary.