删除^ @ Unix文件中的字符 [英] Remove ^@ Characters in a Unix File

查看:342
本文介绍了删除^ @ Unix文件中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于删除不可见字符的问题,只有当我们尝试使用vi命令查看文件时才能看到。我们有一个由Datastage Application生成的文件(Source是一个DB2表 - > Target是一个.txt文件)。文件具有不同数据类型的数据。我遇到一个问题,只有3列,其数据类型定义为CHAR。

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.

如果你打开文本文件夹中的文件,你会看到空格。但是当你通过vi命令在Unix上查看同一个文件时,我们看到^ @字符为蓝色。我的文件是一个分隔符文件,分隔符为^ @ ^(我知道它有点听起来很奇怪)。

If you open the 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) .

我试过:


  1. tr -d [:cntrl:]< Filename> NewFileName - 仍然没有运气 - [分隔符已删除,但空格仍保留]

  2. tr -s^ @< Filename> NewFilename - 仍然没有运气 - 我看到文件大小减少,但隐藏的字符仍然存在。


  3. 使用 seds / ^ @ / g /(和其他sed命令)< Filename - 仍然没有运气。

  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.

推荐答案

vi 中,NUL个字符表示为 ^ @ 。要清除它们:

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

使用 tr 能够删除NUL字符,如下所示:

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

tr -d '\000' < file-name > new-file-name

这篇关于删除^ @ Unix文件中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆