How to remove this symbol "^@" with vim?
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle
--
Chapters
00:00 Question
00:32 Accepted answer (Score 62)
01:55 Answer 2 (Score 53)
03:29 Answer 3 (Score 47)
03:42 Answer 4 (Score 13)
03:59 Thank you
--
Full question
https://superuser.com/questions/75130/ho...
Answer 1 links:
http://en.wikipedia.org/wiki/Byte-order_...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#vim #gvim #findandreplace #symbols
#avk47
ACCEPTED ANSWER
Score 63
You could try:
%s/<CTRL-2>//g
(on regular PCs)%s/<CTRL-SHIFT-2>//g
(on Mac PCs)
where <CTRL-2>
means first press down the CTRL on regular PCs, keeping it as pressed down, hit 2, release CTRL.
and <CTRL-SHIFT-2>
means first press down the control on Mac PCs, keeping it as pressed down, press down shift on Mac PCs, keeping it as pressed down, hit 2, release control and shift.
Finally, both of the two commands should result in %s/^@//g
on screen. ^@
means a single character (a NULL byte, which otherwise couldn’t be displayed), not ^
followed by @
, so you can't just type ^
and @
in a row in the above command.
This command removes all the ^@
.
ANSWER 2
Score 53
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_mark
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
ANSWER 3
Score 52
This actually worked for me within vim:
:%s/\%x00//g
ANSWER 4
Score 13
That 'symbol' represents a NULL character, with ASCII value 000.
It's difficult to remove with vim, try
tr -d '\000' < file1 > file2