In bash or perl, I would like to know how to substitute a null character (0x00) for every white space without changing the white spaces inside the block of double quotes and the white space immediately following a backslash.
Suppose that sample.txt consists of the following line.
"b 1" c\ 2
The above line contains three spaces. However, I would like to replace only the space immediately before c.
The following command undesirably replaced all the three spaces, ignoring quotes and backslashes.
perl -p -e 's/ /\x00/g' sample.txt > null.txt
I need the special meaning of double quotes and backslash to be honored.
Other substitution tools I can think of are the tr and sed commands on bash. However, I do not even know how to substitute a null character using tr or sed.
Many thanks in advance.