When I run
for i in {1..2000}; do sleep 0.1 && echo $(netstat -s | grep -i syns); done | uniq
i can see in realtime when expression $(netstat -s | grep -i syns)
changes.
But when I want to modify output of pipe:
for i in {1..2000}; do sleep 0.1 && echo $(netstat -s | grep -i syns); done | uniq | while read line; do echo $(date) $line; done
the realtime behaviour is lost. How can I use output of uniq
for further manipulations, in particular, append date to each input line change?
uniq
doesn't produce what you call "realtime" output. It emits only unique lines - to do that it has to process the entire set of input lines and remove duplicates. It can't do that until the input is complete, so you won't see any output until the input pipe is closed.man uniq
: Note:uniq
does not detect repeated lines unless they are adjacent. You may want to sort the input first...uniq
is last in piped expression, I see realtime behavior. I don't do sort or count exactly for this purpose