myahya myahya - 2 years ago 199
Bash Question

Replacing Control Character in sed

I need to replace all occurrences of the control character CTRL+A (SOH/ascii 1) in a text file in linux, how can this be achieved in SED?

Answer Source

This can be done through cat with the -v (equivalently --show-nonprinting options and piping this into sed).

If the control character the start of heading (SOH) character (CTRL+A / ASCII 1), and we want to replace it with a tab, we would do the following:

cat -v file | sed 's/\^A/\t/g' > out

cat -v would replace the SOH character with ^A, which would then be matched and replaced in sed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download