sed "undefined label" on MacOS

macos, sed

Solution

The name of the label terminates with the first literal newline, not at the semi-colon. There are two easy ways to solve the problem. Add literal newlines:

 sed '/SUCCESSFUL/d 
    /\[java\]/!b label
    s/\s\+\[java\]//
    /^\s*$$/d; /Compiling/!d
    :label
    /^\s*$$/d
    s/^/monitor: /'

Or use multiple `-e` options:

sed -e '/SUCCESSFUL/d ; /\[java\]/!b label' \
  -e 's/\s\+\[java\]//; /^\s*$$/d; /Compiling/!d' \
  -e':label' -e'/^\s*$$/d; s/^/monitor: /'

Problem

I recently found out that this simple `sed` expression work fine on Linux or under Cygwin but fails on Mac with an "undefined label" error: ``` $ sed '/SUCCESSFUL/d ; /\[java\]/!b label; s/\s\+\[java\]//; /^\s*$$/d; /Compiling/!d; :label /^\s*$$/d; s/^/monitor: /' sed: 1: "/SUCCESSFUL/d ; /\[java ...": undefined label 'label; s/\s\+\[java\]//; /^\s*$$/d; /Compiling/!d; :label /^\s*$$/d; s/^/monitor: /' ``` `sed` on MacOS is a BSD variant with different options than the GNU counterpart. However `man sed` clearly indicates the MacOS version of `sed` supports labels, so why this error, and most important how to solve it?

Original source

Related problems