I have constructed a pipeline that ends with uniq. It repeatedly does an SNMP query and I want to see when the value changes.(while true; do snmpget ...; sleep 1; done) | uniqThis works fine in a terminal, because uniq flushes its output on each line. However, if I then want to add a timestamp, something like(while true; do snmpget ...; sleep 1; done) | uniq | perl -ne 'print scalar localtime, $_'then I don't get any output straight away. It appears that in this case, since uniq is not writing to a terminal, it doesn't bother to flush its standard output until the output buffer gets full.Is there a way to force uniq to flush its output even when not writing to a terminal, so the next step in the pipeline can see each line as it is output from uniq?If it matters, this happens to be on CentOS 5.6 with uniq from GNU coreutils version 5.97.
How can I force uniq to flush its output?
bash;pipe;stdout;uniq