How to detect and delete lines containing ˆ@

grepsedspecial characterstext processing

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?

Best Answer

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.

Related Question