0

This question already has an answer here:

I found out that when I run a command which executes a software that has continuous output lines e.g. traffic monitor like tcpdump or tshark the command keeps counting numbers on screen like 4, 8, 12 ... and so on.

command... | awk -F ' ' '{ANY COMMAND}'

I want my bash script to do actions after every single line of output and not every one thousands of lines. How can I achieve that?

There's a good example when running a software generating a lot of output and you place pipe operator like this:

command... | awk -F ' ' '{print $1}'

It will count numbers from 0 to 1000+ and then it simply prints out all correct information once, but not immediately on script execute.

If I put output into file using:

command... > file.txt

... then data is there immediately when command provides any output. I'm wondering what is causing the delay when using a pipe operator?

marked as duplicate by Kusalananda, jimmij, Community Mar 24 at 18:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

You can use this program (unbiffer) to stop buffering the output of your program:

unbuffer command... | awk ......

The reason you get this "delay" is most of the I/O operation in UNIX and Linux are bufferes

Not the answer you're looking for? Browse other questions tagged or ask your own question.