Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i have some files that are corrupted with this symbol

^@

It's not part of the string, it's not searchable. How do i substitute this symbol with nothing or how do i delete this symbols?

Here is an example line from one file:

^@F^@i^@l^@e^@n^@a^@m^@e^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@:^@ ^@^M^@
share|improve this question

5 Answers

up vote 9 down vote accepted

You could try:

%s/<Ctrl-V><Ctrl-2>//g

share|improve this answer
this removes the nullbytes, thanks – mrt181 Nov 26 '09 at 11:15

I don't think your files are corrupted. Your example line looks like it contains regular text with null bytes between each character. This suggests it's a text file that's been encoded in UTF-16 but the byte-order mark is missing from the start of the file. See http://en.wikipedia.org/wiki/Byte-order%5Fmark

Suppose I open Notepad, type the word 'filename', and save as Unicode Big-endian. A hex dump of this file looks like this:

fe ff 00 66 00 69 00 6c 00 65 00 6e 00 61 00 6d 00 65

If I open this file in Vim it looks fine - the 'fe ff' bytes tell Vim how the file is encoded. Now suppose I create a file containing the exact same sequence of bytes, but without the leading 'fe ff'. Vim inserts ^@ (or <00>, depending on your config), in place of the null bytes; Notepad inserts spaces.

So rather than remove the nulls, you should really be looking to get Vim to interpret the file correctly. You can get Vim to reload the file with the correct encoding with the command:

:e ++enc=utf16

share|improve this answer
Yes, the last command made vim interpret the file correctly but does not remove the nullbytes. – mrt181 Nov 26 '09 at 11:14
3  
To remove them, choose another encoding and save the file again: :set fenc=utf-8 – Scytale Aug 12 '10 at 9:19

This actually worked for me within vim:

:%s/\%x00//g
share|improve this answer
this works with substitute(), but Ctl-VCtl-Shift-2 does not. – dsummersl Jan 18 at 15:26

That 'symbol' represents a NULL character, with ASCII value 000.

It's difficult to remove with vim, try

tr -d '\000' < file1 > file2
share|improve this answer

The accepted solution did not work for me. I made vim pipe the file through tr instead:

:%!tr -d '\000'

This would also work well with visual mode (just type :!tr -d '\000') or on a range of lines:

# Remove nulls from current line:
:.!tr -d '\000'

# Remove nulls from lines 3-5:
:3,5!tr -d '\000'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.