Delete ^ @ Characters in a Unix file

My question is about removing invisible characters, which can only be seen when trying to view a file using the "vi" command. We have a file created by the Datastage application (Source is a DB2 table → Target is a .txt file). A file has data with different data types. I have a problem with three columns whose data types are defined as CHAR.

If you open the file in the text panel, you will see spaces. But when you view the same file on Unix with the vi command, we see the @@ characters in blue. My file is a delimiter file with a delimiter like ^ @ ^ (I know this sounds weird).

I tried:

  • tr -d [:cntrl:] <Filename >NewFileName - Still out of luck - [Separators removed, but spaces remain)
  • tr -s "^@" <Filename >NewFilename - Still no luck - I can see that the file is reducing the file size, but invisible characters remain.
  • I tried changing the separator, but they still see the same invisible characters.
  • Used sed "s/^@/g/" (and other sed commands) <Filename - still no luck.

Any suggestions really appreciated. I researched the posts on this website, but I could not find them. If it's easy, please excuse me and share your thoughts.

+4
source share
1 answer

In vi, NUL characters are represented as ^@ . To get rid of them:

tr

Using tr , you must remove the NUL characters as follows:

 tr -d '\000' < file-name > new-file-name 
+5
source

All Articles