2009-10-29 105 views
0

如何从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添加到上述命令的末尾,但那不起作用。

谢谢。

+0

它以什么方式“不起作用”?什么是所有额外的报价?你可以这样做:'sed -e's/old_word/new_word /'temp_file> output_file 2> error_file' – 2009-10-29 18:18:24

+0

它没有用,因为我使output_file只读并执行了命令。该错误消息仍显示在控制台上。额外的引号是因为old_word和new_word实际上是我脚本中的变量。 – Rohit 2009-10-29 18:33:38

回答

0
sed -e 's/'old_word'/'new_word'/' temp_file > output_file 2>error_file 
0

下面的命令对我的作品般的魅力:

sed -e 's/'old_word'/'new_word'/' temp_file > output_file 2> sed_error 

只要确保你没有把2>之间的空间。