Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove ^@ Characters in a Unix File

I have a question about removing invisible characters which can be only be seen when we try to view the file using "vi" command. We have a file that's being generated by Datastage Application (Source is a DB2 Table -> Target is a .txt File). File has data with different data types. I'm having an issue with just 3 columns which have their datatypes defined as CHAR.

If you open the file in a Textpad you'd see spaces. But when you view the same file on Unix via vi command, we see ^@ characters in blue color. My file is a delimiter file with the delimiter as ^@^ (I know it's kinda sounds weird) .

I have tried:

  1. tr -d [:cntrl:] <Filename >NewFileName — Still no luck — [Delimiters are removed but the spaces remain]
  2. tr -s "^@" <Filename >NewFilename — Still no luck — I see file reduce in file size but the invisible characters still stay.
  3. Tried changing the delimiter — but still see the same invisible characters.
  4. Used sed "s/^@/g/" (and other sed commands) <Filename — still no luck.

Any suggestions are really appreciated. I have researched the posts on this website but I couldn't find one. If it's a simple please excuse me and share your thoughts.

like image 414
Manikanta G Avatar asked Aug 06 '15 02:08

Manikanta G


People also ask

How do I delete a character from a file?

Press Backspace one or more times to delete the characters in front of the cursor.

How do I delete a specific word in Unix?

How do I match and remove (delete) the words “ssh_args=-p 1222” from config file using sed command under Linux or Unix like operating systems? You can use the the substitute sed command changes all occurrences of the “ssh_args=-p 1222”. The same command can be used to delete the required words.

How to remove a specific character from a file in Linux?

1. To remove a specific character, say 'a' $ sed 's/a//' file Linux Solris Ubuntu Fedor RedHt This will remove the first... 2. To remove 1st character in every line: $ sed 's/^.//' file inux olaris buntu edora edHat . (dot) tries to match a... 3. To remove last character of every line : $ sed ...

What does -DC delete special characters mean in Unix?

The first tr deletes special characters. d means delete, c means complement (invert the character set). So, -dc means delete all characters except those specified. The n and r are included to preserve linux or windows style newlines, which I assume you want. How do I remove special characters from a CSV file in Unix?

How to use sed command to delete a specific character?

This sed command finds the pattern and replaces with another pattern. When the replace is left empty, the pattern/element found gets deleted. 1. To remove a specific character, say 'a' This will remove the first occurence of 'a' in every line of the file.

How do I remove special characters from a CSV file in Unix?

How do I remove special characters from a CSV file in Unix? iconv (internationalization conversion) Here is a solution using iconv: iconv -c -f utf-8 -t ascii input_file.csv. … tr (translate) Here is a solution using the tr (translate) command: cat input_file.csv | tr -cd ‘


2 Answers

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

tr

Using tr, you should be able to remove the NUL characters as follows:

tr -d '\000' < file-name > new-file-name
like image 150
Robby Cornelissen Avatar answered Sep 27 '22 15:09

Robby Cornelissen


open the file with vim and then type ':' without the single quote and paste this:

%s/control + 2//g (on regular PCs)

%s/control + shift + 2 //g (on Mac PCs)

of course, replace with keys from your keyboard

like image 25
Moniba Avatar answered Sep 27 '22 16:09

Moniba