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 \'
There are a bunch of similar questions on SO but most of them are due to the behavior of -i
differing between platforms, so this is different.
In this case, the issue is rather simple: it seems like label references can only go backwards in the BSD version of sed
, whereas the GNU version allows to use forward references. That is on MacOS, the :label
must appear before the b label
.
The solution is to rewrite the expression to either define the label before the branch, or in the case of the expression above realize the branch is a kind of "if this pattern is not present ... jump ahead". In this case the expression can be expanded to not need the label in the first place:
sed '/SUCCESSFUL/d ; /\s+\[java\]\s*/d; /\[java\]/s/\s\+\[java\]//; /Compiling/!d; /^\s*$$/d; s/^/monitor: /'