Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is ^@ character in vi?

I am seeing a lot of ^@ character in a contents of a text file on my UNIX server. I am unable to understand what does ^@ mean? and how to remove them from the file? and above all why it is generated?

If i try to see the contents of the file using cat , I am getting this:

u3210#"! utypyado

however if try to use cat -v , i am getting ^@ characters (as attached screenshot) along with some text in english. Same output is observed when i use vi with :set list command.

Any help is much appreciated , thanks very much in advance.

enter image description here

like image 853
PKumar Avatar asked Feb 05 '14 05:02

PKumar


People also ask

How would you find a character in vi?

To find a character string, type / followed by the string you want to search for, and then press Return. vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return.

How do I go to a specific character in vi editor?

If you're already in vi, you can use the goto command. To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file.


2 Answers

As the comments say ^@ is actually a null byte (\x00) in your file.

If you want to get rid of all null byte instances then you can use this command in vi:

:%s/[\x0]//g
like image 160
anubhava Avatar answered Oct 06 '22 05:10

anubhava


You can answer the question yourself: at least, the "what character is this" part, not the "how did it get here" part. From :help ga:

Print the ascii value of the character under the
cursor in decimal, hexadecimal and octal.  For
example, when the cursor is on a 'R':
        <R>  82,  Hex 52,  Octal 122

For more details and related commands, see the full entry.

like image 24
benjifisher Avatar answered Oct 06 '22 04:10

benjifisher