Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing the null character ^@ in a flat file

Tags:

terminal

macos

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.

like image 651
user1575175 Avatar asked Dec 21 '22 09:12

user1575175


2 Answers

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

With tr:

tr -d '\0'
like image 88
Anton Kovalenko Avatar answered Jan 12 '23 15:01

Anton Kovalenko


With sed:

sed 's/\x0/-9/g' filename > newfile
like image 40
Anew Avatar answered Jan 12 '23 16:01

Anew