Replacing the null character ^@ in a flat file

有些话、适合烂在心里 提交于 2020-01-01 15:43:22

问题


I have a flat file generated from someone else's software. They insert the null character ^@ in certain positions of the file. I wish to replace them with something else like -9. How do I search and replace this character efficiently in terminal on Mac OS X?

Thanks.

There is another post addressing this question in linux.


回答1:


(To maintain a SO tradition of proposing multiple answers with different tools for shell scripting questions):

With tr:

tr -d '\0'



回答2:


With sed:

sed 's/\x0/-9/g' filename > newfile


来源:https://stackoverflow.com/questions/14881821/replacing-the-null-character-in-a-flat-file

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