views:

34

answers:

2

Hello,

How do I capture any error from a sed command into a file? Here is the sed command I am using:

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

Now, when everything goes well, modified contents from temp_file are captured in output_file. But let's say that output_file happens to be read only. In this case, instead of error being shown on screen , I would like it to be redirected to error_file. How can I do that? I tried adding 2> error_file to the end of the above command but that did not work.

Thanks.

A: 

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

ennuikiller
A: 

Following command works for me like charm:

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

Just make sure you didn't put space between 2 and >.

Ivan Nevostruev