Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete <0x00> characters in Sublime Text 3?

Problem

So I have this large text file which contains <0x00> characters (see picture below).

Sublime Text 3 with <0x00> including replace option

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.

occurrences found

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.

Progress update #1

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.

progress update 1

Progress update #2 (solution)

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

like image 700
Kamuffel Avatar asked Jul 20 '18 19:07

Kamuffel


1 Answers

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:

Sublime

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.

like image 173
James Parsons Avatar answered Sep 20 '22 17:09

James Parsons