I’m trying to find a way to flush/ignore lines in gawk when it is doing “some work” with a script like the script below:
BEGIN{
c = 1
}
$0 ~ /test/{
if(c == 1){
c = 0
system("sleep 3")
print "up"
c = 1
}
}
Input:
>gawk -f test.awk
test
test
test
up
up
up
Is there a way i can tell gawk to ignore the lines that match the pattern when it is “doing work”, and start processing the first line after it is done? Now it is buffering and when it is done it start processing the lines in the “input buffer”, but it should ignore those lines.
The input buffer is beyond the control of your AWK script.
After the first line is read the sleep is triggered, after the sleep is finished whatever is the next line of input will be read, there is no way (as far as i know and can find) to skip all the input that happened while the sleep was happening.
The closest thing I have seen in C is to do low level non-blocking reads to consume all the immediately available input after each sleep.