在替换之前通过外部程序管道 sed 捕获组?

Pipe sed capture group through external program before replacing?

有没有办法 sed 将捕获组通过管道传递给另一个程序,使正则表达式的 RHS 中的 </code> 等于该程序的输出?</p> <p>例如,运行</p> <pre><code>sed 's/lorem ipsum \(foobar\)//g' file.txt

会通过另一个程序(例如 tr 'o' 'a')将 "foobar" 管道化,使 </code> 成为 "faabar",让 <code>sed 替换 "lorem ipsum foobar" "lorem ipsum faabar"?

这只是一个简单的例子。我意识到我可以在不使用 tr.

的情况下将 "foobar" 转换为 "faabar"

使用执行选项:

e
This command allows one to pipe input from a shell command into pattern space. If a substitution was made, the command that is found in pattern space is executed and pattern space is replaced with its output. A trailing newline is suppressed; results are undefined if the command to be executed contains a NUL character. This is a GNU sed extension.

(source; original source)