How to remove the ^@ character in a file.

I receive a file which is Dos format. When I view the file using vi, I was able to find ^M, ^@ characters in beteen records. I wanted to remove these control/special characters. I used the

dos2unix

command. This removed the ^M characters. But I am unable to remove the ^@ character. I tried even the

sed 's/^@//g'

but no use. Please help me on removing the ^@ character.

Sample File
=========
1|insured^@to bcb^@sm.
Expected Output
=========
1|insuredtobcbsm.

Thanks:o

Can delete nulls with "tr".

cat oldfile | tr -d "\000" > newfile

Hi
Try this

sed 's/\^@/ /g' < filename |tr -d " "

:slight_smile:

I've assumed that you were viewing the file with "cat -v" and seeing each null character as ^@ . sdebasis is assuming two ascii characters ^ and @ .
Please clarify what is in the file:

od -oc filename

Nulls should show as \0 by this method.

1 Like

@Methyl

I was using VI editor to view this file.

Your code

 cat oldfile | tr -d "\000" > newfile 

works!! the ^@ characters were removed.

:slight_smile:

Must have been nulls.

Try this

sed 's/[[:cntrl:]]//g' filename