> I checked out the man page for sed. It indicates to me that the pipe should
> work, based on the statement:
> "The sed utility reads the specified files, or the standard input if no
> files are specified, modifying the input as specified by a list of commands.
> The input is then written to the standard output."
> So, my understanding is that sed should take standard in form vmstat,
> process it, and output standard out. Your statements indicate that I am
> wrong. This newbie would appreciate an explanation.
I'm not saying you're wrong. You're perfectly correct.
My theory is that sed is saving up its output until it fills its output buffer,
probably 4K or 8K bytes, then flushing it all to the pipe in one write. This is
typical behavior for a lot of Unix commands. vmstat by itself is designed to
write one line at a time to standard output and flush its output after each
line, so in the direct vmstat | logger example, logger gets the lines from
vmstat as they are written. When piped through sed, however, the output is
being saved up by sed until it hits that buffer size and then being sent to
logger in one big chunk. You're not seeing anything logged because you're not
waiting long enough for the buffer to be filled.
Many Unix stream processing programs observe whether their output file is a
terminal device and do line buffering if so, and otherwise do block buffering
for efficiency. Read the man page for setbuf or setbuffer for an explanation of
this. To work around this, you'll probably have to come up with some way to
invoke sed only once for each line of input, perhaps piping vmstat into xargs
and invoking an echo | sed | logger pipeline.
> > > I am using FreeBSD 3.3.
> > > The following two pipes work fine:
> > > vmstat -w 5 | logger -p local0.info
> > > vmstat -w 5 | sed -e /procs/d -e /fre/d
> > > But don't work when combined into:
> > > vmstat -w 5 | sed -e /procs/d -e /fre/d | logger -p local0.info
> > > I don't understand why. Any suggestions?
> > Output buffering by sed?
--
Jefferson Ogata : Internetworker, Antibozo