Note that there are some explanatory texts on larger screens.

plurals
  1. POMake sed not buffer by lines
    primarykey
    data
    text
    <p>I'm not trying to prevent sed from block-buffering! I am looking to get it to not even line-buffer. </p> <p>I am not sure if this is even possible at all. </p> <p>Basically there is a big difference between the behavior of <code>sed</code> and that of <code>cat</code> when interacting with them from a raw pseudo-terminal: <code>cat</code> will immediately spit back the inserted characters when it receives them over STDIN, while <code>sed</code> even in raw mode will not. </p> <p>A thought experiment could be carried out: given a simple sed command such as <code>s/abc/zzz/g</code>, sending a stream of input to sed like <code>123ab</code> means that <code>sed</code> <em>at best</em> can provide over standard output the characters <code>123</code>, because it <em>does not yet know</em> if a <code>c</code> will arrive and cause the result string to be <code>123zzz</code>, while any other character would have it print exactly what came in (allowing it to "catch up", if you will). So in a way it's obvious why <code>cat</code> does respond immediately; it can afford to. </p> <p>So of course that's how it would work in an ideal world where <code>sed</code>'s authors actually cared about this kind of a use case. </p> <p>I suspect that that is not the case. In reality, through my not too terribly exhaustive methods, I see that <code>sed</code> will line buffer no matter what (which allows it to always be able to figure out whether to print the 3 z's or not), unless you tell it that you care about matching your regexes past/over newlines, in which case it will just buffer the whole damn thing before providing any output. </p> <p>My ideal solution is to find a <code>sed</code> that will spit out <em>all</em> the text that it has already finished parsing, without waiting till the end of line to do so. In my little example above, it would instantly spit back the characters <code>1</code>, <code>2</code>, and <code>3</code>, and while <code>a</code> and <code>b</code> are being entered (typed), it says nothing, till either a <code>c</code> is seen (prints <code>zzz</code>), or any other character <code>X</code> is seen, in which case <code>abX</code> is printed, or in the case of EOF <code>ab</code> is printed. </p> <p>Am I SOL? Should I just incrementally implement my Perl code with the features I want, or is there still some chance that this sort of magically delicious functionality can be got through some kind of configuration? </p> <p>See <a href="https://stackoverflow.com/questions/16114749/regular-expression-incremental-parsing">another question of mine</a> for more details on why I want this. </p> <p>So, one potential workaround on this is to manually establish groups of input to "split" across calls to <code>sed</code> (or in my case since i'm already dealing with a Perl script, perl's regex replacement operators) so that I can sort of manually do the flushing. But this cannot achieve the same level of responsiveness because it would require me to think through the expression to describe the points at which the "buffering" is to occur, rather than having a regex parser automatically do it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload