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?

  • Just to point it out: the ˆ caret is different from the ^ caret sign. – user13742 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

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

You can delete them using:

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


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.

  • 1
    I realize my answer will not be useful if the file contains literal null characters. Your answer is a better solution. – user13742 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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