关键点:
使用sed 的e选项
示例:
sed -nr ‘s/([^ ]+) (.*)/echo “\1” \2\n/ep’ input
注意s/…../…./ep中的e选项,此句将以input文件内容作为输入,然后进行内容提取(s/([^ ]+) (.*)/
),最后将提取内容作为echo命令的参数并执行命令(e选项),最后将结果输出(p选项)。
Ref:
[1] http://unix.stackexchange.com/questions/48325/how-to-embed-a-shell-command-into-a-sed-expression