Problem
So I have this large text file which contains <0x00>
characters (see picture below).
As you can see on the picture above, I have tryed to remove those characters with a regular expression \x00
. Besides that, I have also tryed \0
and \00
with no success.
However, when I try to replace these characters in Sublime Text, a pop-up shows that these <0x00>
characters indeed have been found (see picture below), so far so good.
Unfortunately, when I click the "replace" button the characters are not replaced.
Question
How can I get rid of these <0x00>
characters?
p.s. It is important to mention that I cannot do a search on "0" since this text file contains zero's, which I would like to remain.
I have managed to copy a <0x00> char into the "find" search box (see picture below).
However, even when I try to replace this character with an empty character inside the text file no changes occur unfortunately.
Without the helping hand of @00 I wouldn't find the answer to this problem, thank you!
Explanation
The file was encoded in UTF-16, but I assumed it was UTF-8. The file was opened in BOM UTF-8, which was exactly the reason why I was not able to delete the <0x00>
(NUL) characters in Sublime Text 3.
Solution
Execute in 'bash' or in a 'terminal' the following command:
sed -i 's/\x0//g' [textfile_name].txt
Ok, I've tried this out myself and it seems that a regular expressions will work. Make sure you have the regex option selection (highlighted in image) and use a regex of \0
:
Now just make sure you have nothing in the replace filed and hit Replace All. The NUL characters should be gone.
NOTE
While reading around, it seems that you have a NUL after every other character which might indicate that the file is actually UTF-16 (and if this is the case, you do not want to remove them) and would need to be reloaded as such. If switching to UTF-16 and my above solution do not work, this thread may be of use to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With