and now with 100% more patch... Index: process.c =================================================================== RCS file: /cvs/src/usr.bin/sed/process.c,v retrieving revision 1.32 diff -u -p -r1.32 process.c --- process.c 22 Feb 2017 14:09:09 -0000 1.32 +++ process.c 24 Sep 2017 21:58:14 -0000 @@ -336,6 +336,7 @@ substitute(struct s_command *cp) int n, lastempty; size_t le = 0; char *s; +int i = 0; s = ps; re = cp->u.s->re; @@ -386,7 +387,7 @@ substitute(struct s_command *cp) * and at the end of the line, terminate. */ if (match[0].rm_so == match[0].rm_eo) { - if (*s == '\0' || *s == '\n') + if (*s == '\0') slen = -1; else slen--;
On 09/24/17 23:57, Martijn van Duren wrote: > This fixes the issue for me, but I'm not sure about the motivation > behind the check. > Maybe schwarze@ can shed some light on it, since he's to (cvs) blame for > the particular line. > > martijn@ > > On 09/24/17 15:42, Andreas Kusalananda Kähäri wrote: >> Hi, >> >> Given the input file of three lines: >> >> line 1 >> line 2 >> line 3 >> >> and the sed script >> >> s/\</\ >> /g >> s/^/hello/ >> >> which inserts a newline in front of every word and then prepends the >> word "hello" to the beginning of the pattern space. >> >> The following happens: >> >> $ sed -f script.sed input.txt >> hello >> >> hello >> >> hello >> >> >> I was expecting to get >> >> hello >> line >> 1 >> hello >> line >> 2 >> hello >> line >> 3 >> >> This is a bit surprising since running only the first sed expression >> gives (as expected) >> >> >> line >> 1 >> >> line >> 2 >> >> line >> 3 >> >> >> The question is, why does the "line N" data disappear when inserting a >> word at the start of the pattern space here? >> >> I'm also noticing that this does not happen if a space (for instance) >> precedes the escaped newline in the first expression: >> >> s/\</ \ >> /g >> s/^/hello/ >> >> >> This is using sed in the base system on OpenBSD 6.1-stable (amd64). >> >> Cheers, >> >