【发布时间】:2015-03-03 13:40:37
【问题描述】:
我想根据文件 $key 中定义的“字符串字符串”对替换文本。
示例输入文件$input
a b c foo
d e f moo
g h i boo
预定义的“密钥”文件$key
cow moo
code foo
ghost boo
cheer woo
期望的输出
a b c code
d e f cow
g h i ghost
我的尝试
perl -pe 's/(.*?)(\woo)/$1qq{grep -oP ".*(?=\s$2)" $key}/e' $input > $output
错误返回
syntax error at -e line 1, near "$1qq{grep -oP ".*(?=\s$2)" $key}"
syntax error at -e line 1, near "s/(.*?)(\woo)/$1qq{grep -oP ".*(?=\s$2)" $key}/ee"
我们将不胜感激。
非常欢迎提出更好的方法来实现预期结果的建议,但理想情况下可以接受的答案还包括解决方案或对使用 perl 替换的评论。
【问题讨论】:
标签: perl grep substitution