0

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?

1 Answers1

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

Romeo Ninov
  • 17,484