I need to tail -f a file output stream and I need to get only lines that contains "get" and "point" in the same line. It doesn't matter the order.
Then I need only the text BEFORE "point".
I have to count each line and perform other serveral actions after this has performed 3 times.
I have done something like this. But I don't know how to go on.
I am currently learning about AWK. I don't know if there's a straight forward way to do this with AWK. It would be nicer to avoid "grep".
One way to do it would be to run the tail/awk pipe in a background subshell, redirect that output to a temp file, and have the parent script terminate the subshell when the file is 3 lines long.
@CarloM: May i ?
Hope my understanding is correct below:
First create a temporary file.
Second, tail the running log and awk looks for get or point string and substitute globally after the point to empty,
pipe the number of fields after substitution to tee command , which shows the output to standard output & file created in first step.
Execute the complete second step in the background.
third one is , store the background process in to variable using shell builtin variable.
Start infinitive loop, pipe the number of lines in tempfile and print the first field using awk.
when test operator checks it greater than 3 then break the loop.
remove the temp file and kill the background process.
It would be simpler to just place the monitored and monitoring code in the same process group and use kill 0 to terminate the entire group.
set -m
exec 3>&2 2>/dev/null
sh 2>&3 <<'EOF'
tail ... | awk ... | tee ... &
while :; do
monitoring-commands
done
cleanup-commands
kill 0
EOF
The highlighted redirections can be omitted if the job control messages aren't a bother.
However, in my opinion, a fifo-based solution is a superior approach. Since reading on a fifo blocks, there's no need for a polling while-loop and explicit sleeps.