Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a simple problem:

In my file, the are lines containing the string ˆ@ˆ@ˆ@ˆ@ˆ@ˆ@. I just want to delete all lines with this string, using for example the sed or grep commands.

And I would like to know why there is such string occurred in my file. What is it meaning for in Linux/Unix world?

share|improve this question
    
Just to point it out: the ˆ caret is different from the ^ caret sign. –  Herman Torjussen Jan 19 '12 at 14:15
    
in my case, it should be the ˆ caret. I may have mixed them. –  jianfeng.mao Jan 19 '12 at 14:38

1 Answer 1

up vote 13 down vote accepted

These ^@ are null characters, which have an ASCII code of 0.

You can delete them using:

tr -d '\000' < myfile > myfile.out

or:

sed 's/\x0//g' < myfile > myfile.out

It's possible that this is a file hole. I have also seen this issue in the past - these null characters appeared in my logs when I was running out of disk space and processes were trying to write to them.

share|improve this answer
    
+1 for explaining what they are –  MaxMackie Jan 19 '12 at 14:56
1  
I realize my answer will not be useful if the file contains literal null characters. Your answer is a better solution. –  Herman Torjussen Jan 19 '12 at 15:13
1  
Sparse files will also output the nul character. But removing them in this way may be undesirable (adding blocks where some did not exist before. Best to check the number of blocks (ls -s) vs (ls -l) or with stat. –  Arcege Jan 19 '12 at 15:41

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.