0

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

  • 2
    Those characters are how a nul byte are displayed, meaning it's a binary file. `.dat` implies it is a binary data file too. Are you sure you're meant to be able to open it with a normal text editor? – Jonathan Wakely Mar 07 '15 at 12:26
  • 2
    You realise that your `sed` command doesn't actually change the file, right? It will print the modified data to stdout, not back to the file. Use `sed -i .bak 2d fort.21.dat` to edit the file in-place, or `sed 2d fort.21.dat > fort.21.txt` to write it to a new file. – Jonathan Wakely Mar 07 '15 at 12:27

1 Answers1

2

Try:

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

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

psmears
  • 26,070
  • 4
  • 40
  • 48