# FreeBSD 11.0 new sed behaviour



## kpect (Oct 15, 2016)

Hello.

Al of a sudden sed began to act differently on FreeBSD 11
    On FreeBSD 11.0 following script (<------> - tab character)
`# cat file`
SEARCHED_LINE


`#cat testscript.sed`
#!/bin/sh
sed -E -i '.orig' \
<------>-e '/^SEARCHED_LINE/ a\
<------>line1\
line2\
<------>\<------>line3' \
file

performs this output:



```
SEARCHED_LINE
<------>line1
line2
<------><------>line3
```

While on FreeBSD 10.3 and previuos versions it performed this:


```
line1
line2
<------>line3
```


Does somebody know why FreeBSD devs have changed pretty sane and convenient sed's behaviour to gsed's one?
My scripts looked very neat and structured with previous BSD sed.
Do I have to rewrite all my scripts now?
Regards


----------



## Oko (Oct 15, 2016)

Check if they did't replace sed with gsed. Check if there is OpenBSD sed in ports and use that one.


----------



## kpect (Oct 15, 2016)

sed has only one hardlink, haven't found gsed in base:


```
$ type sed
sed is a tracked alias for /usr/bin/sed
$ ll /usr/bin/sed
-r-xr-xr-x  1 root  wheel  37784 25 сент. 16:04 /usr/bin/sed
$ gsed
mksh: gsed: not found
```

And no any new key in sed which would switch it's behaviour from GNU to BSD.

Haven't found OpenBSD's sed in ports, while I've found gsed in ports - textproc/gsed.
Then why replicate gsed behaviour in BSD sed?


----------



## Oko (Oct 15, 2016)

kpect said:


> Then why replicate gsed behaviour in BSD sed?


+1


----------



## wblock@ (Oct 15, 2016)

First guess would be internationalization.


----------



## marino (Oct 15, 2016)

when it doubt, explicitly set collation, e.g. `env LANG=c sed <arguments>`


----------



## jrm@ (Oct 15, 2016)

Oko said:


> Check if there is OpenBSD sed in ports and ise that one.


OpenBSD and FreeBSD 11.0 give the same output with the leading tabs.


----------



## tobik@ (Oct 15, 2016)

Oko said:


> Check if they did't replace sed with gsed. Check if there is OpenBSD sed in ports and ise that one.


How will this help? OpenBSD 6.0's sed behaves the same way.


----------



## Oko (Oct 15, 2016)

tobik said:


> How will this help? OpenBSD 6.0's sed behaves the same way.


In the past a few userland tools in FreeBSD got replaced with GNU versions then they were revert back to BSD versions. I was sleepy when I answered the original post but not so sleepy not to know that OpenBSD version of sed is true BSD version (I even know the guy who maintaining it). Thus I posted quick answer. I will make sure I keep my tongue in check


----------



## scottro (Oct 16, 2016)

Actually, your fingers, if we're going to be literal.    <ducks and runs away>


----------



## kpa (Oct 16, 2016)

Your example is a little bit complicated there was another thread of a similar sort recently:

Thread 57539

In a nutshell, the new behaviour of sed(1) is not to output a newline when the input hasn't any. Is your example related to this change as well?


----------



## kpect (Oct 16, 2016)

No, it doesn't relate to Thread 57539

There's nothing complicated actually, I just wanted to highlight that classic BSD behaviour for a/c/i operands has been changed silently in 11.0 and it's very uncomfortable for some people.


----------

