Mandatory Programmer Mandatory Programmer - 3 years ago 256
Linux Question

Output of sed in linux won't write to file

Possible Duplicate:

Sed command find and replace in file and overwrite file doesnt work, it empties the file!

Ok so I've got this:

sed "s/^/getHtmlBody\(\"\/NmConsole\/Reports\/Workspace\/Virtualization\/WrVMwareHostList\/WrVMwareHostList.asp\?sGroupList=1'/g" out.bat | sed "s/$/\';--\");/g" >out.bat

And as you can see I'm trying to out into out.bat but it isn't working for some reason - nothing gets displayed on the screen but nothing is written to the file.

What am I doing wrong?

Answer Source

When Bash sees "> out.bat" it truncates the file. The file is now empty, so sed doesn't find the beginnings nor ends of any lines and nothing gets put into out.bat

kojiro's link and codaddict has a nice description plus ways to get around it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download