-1

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/^@//'
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
puk
  • 16,318
  • 29
  • 119
  • 199
  • that's likely not that string but the viewer showing you what is likely a null byte (value 0). see https://superuser.com/questions/287997/how-to-use-sed-to-remove-null-bytes ? – Joe Jul 21 '20 at 21:27
  • This answer is talking about ^A but you could use the same exact method for ^@ which is \x00 https://stackoverflow.com/a/15421538/2193968 or https://stackoverflow.com/a/13180336/2193968 – Jerry Jeremiah Jul 21 '20 at 21:41

1 Answers1

1

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.

agc
  • 7,973
  • 2
  • 29
  • 50