How to replace special characters?

I tried this code and got following:

 
$ echo -e '\0205' | od -bc
0000000 205 012
        205  \n
0000002

I am really new for unix, so I can not understand ths result, would you please explain this result for me.

many thanks

:wall:

Your mainframe originated text has four "special" characters in it: 2 x (^M) and 2 x (M-^E).
^M (control M) is one (of many) representation of the <carriage reurn> ASCII character, others are <CR>, 0x0D (hexadecimal), \0015 (octal), or 13 (decimal).
M-^E represents <Meta><control>E, which is the fifth character above the 128 (ASCII) limit, equivalent to 0x85 (hex), \0205 (oct), or 133 (dec).
So this is what you need to find and replace: a pattern of
^M,M-^E, ^M, M-^E

  • or -
    0x0D,0X85,0x0D,0x85
  • or -
    \0015,\0205,\0015,\0205.
    Most of the proposals given can do that but some where doing it only partly. Sometimes, although, you need to adapt the way the pattern is communicated to the resp. command.

Below a simple example just to help you to understand in which way the 205 sequence is removed from a simple string (here : 'AA')

See the command that ares paste and pay attention to the result it gives :

$ echo -e "A\0205A" | cat -v
AM-^EA
$ echo -e "A\0205A" | tr -d '\205' | cat -v
AA
$ echo -e "A\0205A" | od -bc
0000000 101 205 101 012
          A 205   A  \n
0000004
$ echo -e "A\0205A" | tr -d '\205' | od -bc
0000000 101 101 012
          A   A  \n
0000003
$
awk '{gsub(sprintf("%c%c%c%c",13,133,13,133),"")}1' 

will remove your pattern form your file.

That's taking the scenic route to your destination. AWK strings and regular expressions both support octal escape sequences.

Since the string generated is a constant, there's no need for sprintf. Just use a simple string literal:

sprintf("%c%c%c%c", 13, 133, 13, 133) --> "\15\205\15\205"

However, why even use a string at all when the first parameter to gsub is a regular expression?

gsub(/\15\205\15\205/, "")

Regards,
Alister

I like scenic routes, esp. along the coast, esp. during sunset... thanks for pointing out. I was a bit short sighted...