如何从sed
命令中捕获任何错误到文件中?这里是sed
命令我使用:从sed命令中捕获错误流
sed -e 's/'old_word'/'new_word'/' temp_file > output_file
现在,当一切都顺利的话,从temp_file
修改的内容在output_file
抓获。但是让我们假设output_file
恰好是只读的。在这种情况下,我不希望将错误显示在屏幕上,而是将其重定向到error_file
。我怎样才能做到这一点?我试着将2> error_file
添加到上述命令的末尾,但那不起作用。
谢谢。
它以什么方式“不起作用”?什么是所有额外的报价?你可以这样做:'sed -e's/old_word/new_word /'temp_file> output_file 2> error_file' – 2009-10-29 18:18:24
它没有用,因为我使output_file只读并执行了命令。该错误消息仍显示在控制台上。额外的引号是因为old_word和new_word实际上是我脚本中的变量。 – Rohit 2009-10-29 18:33:38