Re: Standard output piping problem

From: Netocrat (netocrat_at_dodo.com.au)
Date: 05/29/05


Date: Sat, 28 May 2005 23:36:51 GMT

Bill Marcum wrote:

> On Sat, 28 May 2005 20:20:57 GMT, Netocrat
> <netocrat@dodo.com.au> wrote:
>>
>> $ /usr/sbin/pppstats -w 1 | sed {s/foo//}
>> IN PACK VJCOMP VJUNC VJERR | OUT PACK VJCOMP VJUNC
>> NON-VJ
>> 247460383 589368 0 0 0 | 169639067 621658 0 0
>> 621658
>>
>> BUT:
>>
>> $ /usr/sbin/pppstats -w 1 | sed {s/foo//} | grep "" -
>> [no results]
>> $ /usr/sbin/pppstats -w 1 | grep "" - | sed {s/foo//}
>> [no results]
>>
>> Why won't the multiple pipes present output?
>>
>>
> Because you are not waiting long enough for the buffers to fill?

True... Barry in his reply suggested that it's a buffering issue and to test
this I let the script run for a few minutes. Eventually I got output in a
rush.

> Besides, you don't need grep when sed is in the pipe (but this is
> obviously just an example, maybe your real script uses something other
> than grep?)

Truth be told I was going to use grep as it was simpler than working out how
to remove empty lines with sed. As it turns out it probably wasn't due to
these issues...

So the script I wanted to use ultimately is:

#!/bin/sh
/usr/sbin/pppstats -w 1 |
sed "{s/\([[:space:]]*\([0-9]*\).*|[[:space:]]*\([0-9]*\).*\)/\2 \3/}" |
grep -v ^[[:space:]]$ -

This works correctly but the buffering delays the output which I want in
realtime, so either I don't use grep or I find a way to modify buffering.
The first option seems most appropriate and portable.

I need to find out how to achieve the task of removing lines consisting of
simply a space with the sed script rather than the final grep pipe. I'll
work on it, but if anyone can post a quick solution that'd be great.



Relevant Pages

  • Re: Find a line in a text file then print a field
    ... Here is "grep" part of my perl script so far (ommitting the various ... the matching lines in an array. ...
    (perl.beginners)
  • Re: [PATCH] kconfig: simplification of scripts/extract-ikconfig
    ... I found a way to work around the differences in behavior of grep. ... I've rewritten the extract-ikconfig script to extract the kernel ... -# GNU General Public License for more details. ...
    (Linux-Kernel)
  • Re: Redirect question
    ... In ksh if I enter this command ... It's an issue of buffering. ... When you run grep without re- ...
    (comp.unix.questions)
  • Re: I need a custom script to extract data from my web logs.
    ... >> You aren't passing anything to awk and you don't need awk anyway. ... My original script was using awk to output the data by ... > piping the output of the original grep through awk to the printf. ... (i.e. searchlogs log???? ...
    (comp.unix.shell)
  • Re: modifying files using script
    ... specific string with another one. ... This script works well for one file but exits after that. ... so I used fgrep in the example (grep -F may be preferable or required ... as string by fgrep and RE by $editor, ...
    (comp.unix.shell)