I have a log/text file which is full of highlighted ^B lines when opened with less. Usually I see ^A and I have the following sed command to replace ^A with |. I found it a while ago and do not know how it works.
sed 's/\x1/\|/g'
This seems to be the first time I have seen ^B and the sed command does not work for it.
How can I modify my sed command to handle ^A, ^B or any other possible combination?
^B is \x2, so you can just change your \x1 to \x2 to fix it. More generally, you can use "man ascii" to see the entire ASCII table and find out that ^B (hex 02) is hex 40 less than B (hex 42). Similarly, ^[ (ESC, hex 1B) is hex 40 less than [ (hex 5B).
To handle a range of characters, use brackets. For example, sed 's/[\x1-\x1f]/|/g' will replace all low-numbered control characters with vertical bars.