9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Ingo Krabbe <ikrabbe.ask@gmail.com>
To: <9fans@9fans.net>
Subject: Re: [9fans] p9p sed vs linux sed
Date: Wed, 12 Aug 2015 13:35:36 +0200	[thread overview]
Message-ID: <55945c6c91ffdd9cada6401af5f9ff08@krabbe.dyndns.org> (raw)
In-Reply-To: <20150812081302.GA886@polynum.com>

Luckily plan9 is not POSIX and actually sed does not really add a newline character, it just puts a newline to the end of each pattern buffer, that is done line-wise anyway. Also sed's little brother ed behaves the same, which makes the behaviour even more convenient

term% echo -n 'abc' > inp
term% cat inp
abcterm% ed inp
'\n' appended
4
wq
4
term%

And that is even consistent with (POSIX?) ed on linux systems or anywhere else.

There is a very good reason to do so: The rule just applies to the end-of-input! So when you output a pattern from the sed buffer, you would need to check each time if we are at the end or not and add the newline or not, if it has been there or not. All those branches for just one character at the end of the input that can be easily removed if you really don't want it.

So for simplicity there are very good reasons to state that any output from sed will end in a newline, even if the input doesn't.

If you seek for a sed like thing that does not work line oriented, use ssam, as sam and the streamed version ssam, process input in another way, that is not line oriented.

cheers
ingo

> On Wed, Aug 12, 2015 at 09:57:18AM +0200, Rudolf Sykora wrote:
>> On 12 August 2015 at 09:48, Ingo Krabbe <ikrabbe.ask@gmail.com> wrote:
>>
>> > Actually sed is a line based command and should add a newline, imho.
>>
>> I don't think it should add anything. For itself it should be able to count
>> newlines (because of the possible use of addresses), but otherwise it
>> should not do anything extra (it should be possible to pipe through
>> two seds, for instance).
>>





  parent reply	other threads:[~2015-08-12 11:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-12  7:39 Rudolf Sykora
2015-08-12  7:48 ` Ingo Krabbe
2015-08-12  7:57   ` Rudolf Sykora
2015-08-12  8:13     ` tlaronde
2015-08-12  8:23       ` Rudolf Sykora
2015-08-12 11:35       ` Ingo Krabbe [this message]
2015-08-12 12:39         ` Rudolf Sykora
2015-08-12 13:47           ` lucio
2015-08-12 14:22             ` Rudolf Sykora
2015-08-12 14:29               ` Ingo Krabbe
2015-08-12  7:58   ` Ingo Krabbe
2015-08-14 14:59 ` Alexander Kapshuk
2015-08-15  2:27   ` erik quanstrom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55945c6c91ffdd9cada6401af5f9ff08@krabbe.dyndns.org \
    --to=ikrabbe.ask@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).