我想将块大小转换为MB。我在替换中使用了/e选项。当我在替换部分中添加起始MB时,它会给我错误。
例如:
这是可行的。
echo "16777216 SELECT" |perl -lane 's#(\d+)(\s+SELECT)#$1/(1024*1024*2)#e; print'
8这给了我错误。
echo "16777216 SELECT" |perl -lane 's#(\d+)(\s+SELECT)#$1/(1024*1024*2) MB $2#e; print'
Bareword found where operator expected at -e line 1, near ") MB"
(Missing operator before MB?)
syntax error at -e line 1, near ") MB "
Execution of -e aborted due to compilation errors.能帮我修好第二个吗?
发布于 2010-10-13 21:15:56
perl开关将替换表达式转换为正则/e表达式。您需要引用' MB'并使用连接(.)。
's#(\d+)(\s+SELECT)#$1/(1024*1024*2) . q[ MB] . $2#e应该行得通。
发布于 2010-10-13 21:13:13
变化
(1024*1024*2) MB $2至
(1024*1024*2)."MB".$2/e修饰符告诉引擎将替换字段视为Perl代码。
https://stackoverflow.com/questions/3923967
复制相似问题