[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sed -> needs to wait for EOF?
From: |
Stepan Kasal |
Subject: |
Re: sed -> needs to wait for EOF? |
Date: |
Thu, 16 May 2002 07:03:06 +0000 (UTC) |
User-agent: |
slrn/0.9.6.2 (Linux) |
Hallo,
On Thu, 16 May 2002 12:11:45 +1000, address@hidden wrote:
> It seems that you can't use sed when following a file.
>
> Example:
>
> tail -f /tmp/foo | sed -e s/foo/bar/g &
> echo 123foo456 > /tmp/foo
>
> You would expect that 123bar456 would be printed to your screen somewhere by
> the tail command, but it's not.
>
> My only conclusion here is that sed needs the EOF before it can print
> anyhting, I came to this conclcusion because if you are not doing a -f on your
> tail, then it works fine.
Your conclusion is wrong--try this:
$ sed -e s/foo/bar/g
123foo456
123bar456
No EOF but immediate response!
The reason is that input is buffered unless it's read from terminal.
On my host (linux/i386) this means that you have to write at least 8KB of data
to see any output. Try this (with bash shell):
$ touch /tmp/foo
$ tail -f /tmp/foo | sed -e s/foo/bar/g &
$ for f in {0,1}{,1}{,1}{,1}{,1}{,1}{,1}{,1}{,1}{,1}; do
echo 123foo456 >>/tmp/foo; done
You need to tell sed to process the input unbuffered, as if it was a terminal.
This was recently discussed in gnu.utils.bug under the subject
"[PATCH] sed unbuffered."
(I hope you won't mind if I mail you the posts.)
In short: you can either use a patch to sed, or use ptybandage from ptyget
package. (http://multivac.cwru.edu./ptyget/)
Hope this helps,
Stepan