Explanation of difference between GNU sed and BSD sed

2.6k Views Asked by At

I wrote the following command

echo -en 'uno\ndue\n' | sed -E 's/^.*(uno|$)/\1/'

expecting the following output

uno

This is indeed the case with my GNU Sed 4.8.

However, I've verified that BSD Sed outputs



Why is that the case?

1

There are 1 best solutions below

1
Jarek On

I'd say that BSD's sed is POSIX-compatible only. POSIX specifies support only for basic regular expressions, which have many limitations (e.g., no support for | (alternation) at all, no direct support for + and ?) and different escaping requirements.

BSD sed is default one on MacOS so very first thing on a new system is to get GNU-compatible sed: brew install gsed.