删除^ @ Unix文件中的字符

编程入门 行业动态 更新时间:2024-10-28 14:22:31
本文介绍了删除^ @ 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) .

我试过:

  • tr -d [:cntrl:]< Filename> NewFileName - 仍然没有运气 - [分隔符已删除,但空格仍保留]
  • tr -s^ @< Filename> NewFilename - 仍然没有运气 - 我看到文件大小减少,但隐藏的字符仍然存在。
  • 使用 seds / ^ @ / g /(和其他sed命令)< Filename - 仍然没有运气。
  • tr -d [:cntrl:] <Filename >NewFileName — Still no luck — [Delimiters are removed but the spaces remain]
  • tr -s "^@" <Filename >NewFilename — Still no luck — I see file reduce in file size but the invisible characters still stay.
  • Tried changing the delimiter — but still see the same invisible characters.
  • 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文件中的字符

    本文发布于:2023-10-08 23:51:27,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1474114.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:字符   文件   Unix

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!