Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed: how to replace \0, but not \\0

I'm doing a migration from mysql to postgres. As part of that I'm processing the mysql dump using sed before loading that into postgres.

My MySQL dump has some \0 characters and postgres doesn't like them. So I'm replacing them using a space.

sed 's/\\0/ /g' $dumpfile

Noticed an issue when the line has 320.48k\\02. Easy Listening.

$ echo '320.48k\\02. Easy Listening' | sed 's/\\0/ /g'
320.48k\ 2. Easy Listening

Thats not what I quite wanted. \\ characters are followed by 0 is not a null character. and I want to keep as it is.

Any sed experts around to help?

like image 743
Anand Chitipothu Avatar asked Dec 03 '22 22:12

Anand Chitipothu


1 Answers

If you want to replace null characters (\0), you can use:

sed 's/\x0/ /g'

or

tr '\0' ' '

I use a lot

tr '\0' '\n'< /proc/13217/environ 

to display environment of a process

like image 91
BOC Avatar answered Dec 29 '22 08:12

BOC