我正在尝试使用perl one liner为数字添加1000。这是我试过的:
perl -pi -e "s/ZZZ(\d+)ZZZ/ZZZ\1+1000ZZZ/e" file.txt
我希望将1000
添加到ZZZ
之间的数字。但我收到错误消息:
Backslash found where operator expected at -e line 1, near "ZZZ\"
Bareword found where operator expected at -e line 1, near "1000ZZZ"
(Missing operator before ZZZ?)
syntax error at -e line 1, near "ZZZ\"
Execution of -e aborted due to compilation errors.
感谢您的帮助!
答案 0 :(得分:6)
使用$1
并使用连接在RHS上构建一个新字符串:
perl -pi -e 's/ZZZ(\d+)ZZZ/ZZZ . ($1 + 1000) . ZZZ/e' file.txt
注意:这不适用于perl -Mstrict