Issue
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.
Solution
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 '\0' <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 \0 A \0 i \0 r \0 Q \0 u \0 a \0 l \0 i
0000020 \0 t \0 y \0 S \0 t \0 a \0 t \0 i \0 o
0000040 \0 n \0 E \0 o \0 I \0 C \0 o \0 d \0 e
0000060 \0 \n \0 D \0 E \0 H \0 E \0 0 \0 4 \0 4
*
0000400 \0 \n \0 D \0 E \0 H \0 E \0 0 \0 4 \0
0000420 4 \0 \n \0 D \0 E \0 H \0 E \0 0 \0 4 \0
*
0422160 4 \0 \n \n
0422164
Answered By - Jim Stewart