sed “undefined label” on MacOS

前端 未结 2 1557
温柔的废话
温柔的废话 2021-02-06 00:52

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 \'         


        
2条回答
  •  有刺的猬
    2021-02-06 01:30

    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: /'
    

提交回复
热议问题