I am trying to remove “^@” from multiple text files using Unix platform. I have already found this solution, but it does not work for my case. I also used sed -i -e 's/^@//g' testfile.txt
and dos2unix testfile.txt
.
sample data are put here.
Any suggestion would be appreciated.
Advertisement
Answer
The ^@
that you’re seeing isn’t a literal string. It’s an escape code for a NUL (character value 0). If you want to remove them all:
tr -d '' <test.txt >newfile.txt
To help diagnose this sort of thing, the od
(octal dump) utility is handy. I ran this on the test file you linked, to confirm that they were NULs:
$ od -c test.txt | head 0000000 A i r Q u a l i 0000020 t y S t a t i o 0000040 n E o I C o d e 0000060 n D E H E 0 4 4 * 0000400 n D E H E 0 4 0000420 4 n D E H E 0 4 * 0422160 4 n n 0422164