40
10
What is the sed
incantation to remove null bytes from a file? I'm trying:
s/\000//g
but that is stripping out strings of zeroes.
s/\x00//g
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.
1Works for me™. Also useful:
-i
parameter to convert file in place. – zbyszek – 2016-04-19T19:20:21.063tr < file-with-nulls -d '\000' > file-without-nulls
works beautifully – Paul Carlton – 2017-11-02T18:17:11.460According to the documentation for GNU sed,
\xxx
can be used to produce a character whose hexidecimal value isxx
. To produceNULL
, use\x00
. – Alexej Magura – 2018-07-30T21:22:33.57310that looks like a very incomplete answer. why would it work on some occasions and not others, and if so then wouldn't an example be useful? – barlop – 2011-05-24T19:11:39.437
@barlop: Because of the way it is implemented? The OP didn't specify one and I'm not going to enumerate every single implementation... – Tamara Wijsman – 2011-05-24T20:50:13.013
4Well that then sounds fine to me, so you're saying it depends on the implementation of SED. If you hadn't said that you'd have left open the possible suggestion that one implementation of SED may remove nulls from one file and not another file, depending on the data in the file. – barlop – 2011-05-24T22:03:03.483
3shouldn't it be "tr -d '\000' < file-with-nulls > file-without-nulls" ? – Seamus Abshere – 2013-07-12T19:32:04.210
I needed to convert nul to newline,
sed 's/\x0/\n/g'
worked for me – doug65536 – 2014-02-07T07:33:55.193