How to replace “^@” with “\r” [duplicate]

♀尐吖头ヾ 提交于 2019-12-23 17:20:10

问题


I have a script contains certain functions/replaces,etc..

But in my output, contains some junks like ^@.

How to replace this ^@ with a newline? with the script

This command executes in vim commandline %s/<CTRL-2>//g, but not by script


回答1:


^@ is ASCII 0.

You could use:

sed 's/\x00/\n/g'



回答2:


type command in vim

If you want to fix the result, you could do this in vim:

:%s/

then press:

<Ctrl-V>010

After that your command looks like: :%s/^@

Then you can continue typing:

:%s/^@/\r/g

But I think the better solution is fixing the codes which generated these chars.

in script

If you want to do it in script, there is function : nr2char() you could do nr2char(10) to get the ^@



来源:https://stackoverflow.com/questions/34290247/how-to-replace-with-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!