[Bug 247930] sed pattern space deleted upon leading insertion

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sun Jul 12 11:19:23 UTC 2020


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247930

            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 at FreeBSD.org
          Reporter: lhoursquentin at gmail.com

When adding leading text with `s/^/some text/`, if the pattern space contains
multiple lines with the first one being empty then the pattern space remaining
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$
```

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


More information about the freebsd-bugs mailing list