Getting different results from sed on FreeBSD 12.2 vs. FreeBSD 13.0 vs. Linux

Trying to use extended regular expressions and I'm getting mixed results (neither of which is correct) between FreeBSD 12.2 and 13.0 vs Linux (working).

FreeBSD 12.2:
# echo 'abcd' | sed -r 's/(\w)(.*)/\1/'
abcd

FreeBSD 13.0:
# echo 'abcd' | sed -r 's/(\w)(.*)/\1/'
sed: 1: "s/(\w)(.*)/\1/": RE error: trailing backslash (\)

Linux:
# echo 'abcd' | sed -r 's/(\w)(.*)/\1/'
a

Can someone tell me what I'm doing wrong?

Update: If I install 'gsed' it works perfectly!!!
 
I porting all my bash scripts to FreeBSD so I suppose I better not trust the builtin awk and I better install and use gawk instead.
 
Back
Top