-1

I have a file which has ^@ in it and I am unable to remove it using sed or replace command in python. I can see ^@ only when I open the file in vi editor. Please suggest. Below is what i tried using sed.

sed 's/^@/?/g' filename

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
ankitpandey
  • 339
  • 1
  • 7
  • 23

1 Answers1

2

Tested on Linux, not sure if syntax varies elsewhere, try

$ printf 'abc\0baz\n' | cat -v
abc^@baz
$ printf 'abc\0baz\n' | tr -d '\0' | cat -v
abcbaz

tr will delete all ASCII NUL characters from input.. cat -v is used here to highlight non-printing characters

for file input, use tr -d '\0' <filename


GNU sed (and possibly few other implementations) allow to use hex value to represent a character

$ printf 'abc\0baz\n' | sed 's/\x00//g' | cat -v
abcbaz

so, for in-place editing, use sed -i 's/\x00//g' filename (See also: sed in-place flag that works both on Mac (BSD) and Linux )

Sundeep
  • 23,246
  • 2
  • 28
  • 103