Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Jul 2020 11:19:23 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 247930] sed pattern space deleted upon leading insertion
Message-ID:  <bug-247930-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D247930

            Bug ID: 247930
           Summary: sed pattern space deleted upon leading insertion
           Product: Base System
           Version: 12.1-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: lhoursquentin@gmail.com

When adding leading text with `s/^/some text/`, if the pattern space contai=
ns
multiple lines with the first one being empty then the pattern space remain=
ing
lines are deleted (case 2 below).

One line reproducer:
```
sh$ echo content | sed 'H; g; s/^/preceding/'
preceding

sh$
```

More complete examples:

1 - Non empty first line case

```
s/.*/1st line\
2nd line\
3rd line/

l
i \
-----

s/^/some preceding text /

l
```

```
sh$ echo | sed -nf non-empty-first-line.sed
1st line$
2nd line$
3rd line$
-----
some preceding text 1st line$
2nd line$
3rd line$
```

2 - Empty first line case (the actual bug)

```
s/.*/\
2nd line\
3rd line/

l
i \
-----

s/^/some preceding text /

l
```

```
sh$ echo | sed -nf empty-first-line.sed
$
2nd line$
3rd line$
-----
some preceding text $
$
```

3 - Empty first line case workaround

```
s/.*/\
2nd line\
3rd line/

l
i \
-----

s/.*/some preceding text &/

l
```

```
sh$ echo | sed -nf empty-first-line-workaround.sed
$
2nd line$
3rd line$
-----
some preceding text $
2nd line$
3rd line$
```

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-247930-227>