How to use sed to remove null bytes


What is the sed incantation to remove null bytes from a file? I'm trying:


but that is stripping out strings of zeroes.


seems to have no effect. I'm trying to do this in a sed script, so I'm not sure the echo trick will work.

Best Answer

I don't know how you can exactly achieve this with sed, but this is a solution that works with tr:

tr < file-with-nulls -d '\000' > file-without-nulls

This is a solution for sed that works with some (but not all) implementations of sed:

sed 's/\x0//g' file1 > file2

This is a solution that involves replacing into space characters which should work in all occasions:

sed 's/\x0/ /g' file1 > file2
Related Question