Search code examples
sedasciibinaryfilesnano

Remove '^@' line from a file


I have a file in which I have a particular line of this type:

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^ ...

Actually all the others lines are a list (a matrix) of numbers or *******. The problem is that I can not be able to open this file with normal editors and so I can not be able to remove this line.

I can open the file via shell using nano.

To eliminate this line (that is the second line from the top) I used the simple command:

sed '2d' fort.21.dat

But I can not be able to eliminate it.

Can someone help me to eliminate this line and make this file.dat normally readable ?

Thanks a lot


Solution

  • Try:

    tr -d '\0' < fort.21.dat > fixed.21.dat
    

    This uses the tr utility to delete the ^@ (zero) bytes from the file.