Replacing control characters in HPUX

Hello dears,

Please tell me how can I replace control characters with normal string. I have a file that contains normal string and ^A ^C control characters. I tried to use sed and awk without any luck.

sed 's/^A/foo/g' text > text1         //not worked
sed 's/\x01/foo/g' text > text1      //not worked
sed 's/\x001/foo/g' text > text1     //not worked
sed 's/\001/foo/g' text > text1       //not worked

Used grep to find ^A characters, but it's not finding. tr tool is working fine. But if I use tr it will completely remove all control characters from file. But I need to change control characters with normal string. How can I achieve this. Please help me

OS version - HPUX 11.31
Shell - /usr/bin/sh

Thanks

You can use

sed 's/^A/foo/g' file > newfile

but you need to enter ^A with CTRL-V CTRL-A .

1 Like

Hi,

You mean change command like this:

sed 's/CTRL-V CTRL-A/foo/g' text > newfile

That's right?

---------- Post updated at 04:41 PM ---------- Previous update was at 01:49 PM ----------

Tried it but no luck.

He meant entering CTRL-V+CTRL-A giving you a ^A character displayed which is not the same as entering ^+A

Post the output of cat -vet text on your input file here...

Thanks all,

Problem solved by sed tool. Here is the solution.

sed 's/\^/^^/g' input.txt | cat -v | sed -e 's/\^A/HEAD/g' -e 's/\^\^/^/g' > output.txt

Or you can use dos2ux

dos2ux inputfile > outputfile