sed error: “invalid reference \1 on `s' command's RHS”

后端 未结 4 577
一整个雨季
一整个雨季 2020-12-04 20:38

I run several substitution commands as the core of a colorize script for maven. One of the sed commands uses a regular expression which works find in the shell

4条回答
  •  青春惊慌失措
    2020-12-04 21:08

    You need escape the / after the .

    sed -e "s/\([a-zA-Z0-9.\/\\ :-]\+\)/\1/g"
    

    Or if you don't want to worry about escaping, use |

    sed -e "s|\([a-zA-Z0-9./\\ :-]\+\)|\1|g"
    

    EDIT:

    sed -e "s|WARNING: \([a-zA-Z0-9.-/\\ :]+\)|${warn}WARNING: \1${c_end}|g"
    

提交回复
热议问题