I need to replace some non-printable characters with spaces in file.
Specifically, all characters from 0x00
up to 0x1F
, except 0x09
(TAB), 0x0A
(new line), 0x0D
(CR)
Up until now, I just needed to replace 0x00
character. Since my previous OS was AIX (without GNU commands), I can't use sed
(well, I can but it had some limitations). So, I found next command using perl
, which worked as expected:
perl -p -e 's/\x0/ /g' $FILE_IN > $FILE_OUT
Now I'm working on Linux, so I expected to be able to use sed
command.
My questions:
Is this command appropriate to replace those characters? I tried, and it seems to work, but I want to make sure:
perl -p -e 's/[\x00-\x08\x0B\x0C\x0E-\x1F]/ /g' $FILE_IN > $FILE_OUT
I thought
perl -p
works assed
. So, why does the previous command work (at least, it doesn't fail), and next one doesn't?sed -e 's/[\x00-\x08\x0B\x0C\x0E-\x1F]/ /g' $FILE_IN > $FILE_OUT
It tells me:
sed: -e expression #1, char 34: Invalid collation character
perl -p
prints end product ofstdin
after doing the operations you desire, in this case it's just replacement.sed
's regex might be different thanperl
.