我正在尝试使用perl one liner为数字添加1000.这是我尝试过的:
perl -pi -e "s/ZZZ(\d+)ZZZ/ZZZ\1+1000ZZZ/e" file.txt
Run Code Online (Sandbox Code Playgroud)
我希望这会增加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.
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
使用$1串联在RHS上使用和构建新字符串:
perl -pi -e 's/ZZZ(\d+)ZZZ/ZZZ . ($1 + 1000) . ZZZ/e' file.txt
Run Code Online (Sandbox Code Playgroud)
注意:这不起作用 perl -Mstrict