Search code examples
sedsymbols

How do you remove ^@ with sed?


I am trying to parse some logs and there is a strange ^@ symbol in there. I can remove it in by cutting that character and paste/searching for it, but how do I remove it in the bash command line automatically.

This doesn't work

sed 's/^@//'

Solution

  • When faced with an unwanted byte in a text file represented by some other stand-in symbol, a tool like hexdump or od helps. Try this:

    1. Make a copy of the original file.

    2. Remove everything in the copied file, except a line or two that includes the mystery symbol. Save the file.

    3. To see what the byte really is, do:

      hexdump -v  -e '/1  "%_ad#  "' -e '/1 " _%_u\_\n"' file
      
    4. From which listing find the hex code for the unwanted byte, (let's say it's 00), and try:

      sed 's/\x00//' file
      

    If that works, run the same sed line on the original file.