onlyf onlyf - 1 year ago 104
Perl Question

Transliterate Characters in Hex in Bash

i have a set of hexadecimals that i d like to transliterate to another set of hexadecimals, in example :

x00 -> x20
xB0 -> x20
x21 -> x40
x80-xFF -> x20
x22 -> x43

I know i can chain sed statements like :

sed -i.bak $'s/[\x80-\xFF]/\x20/g'

or like :

sed -e 's/\x00/\x20/g;s/\xB0/\x20/g'

but is there a way to "break" those separate changes by line so its more readable? Like :

sed -e '
' File_In > File_out

If its not possible, could this be done with perl? Thank you.

Answer Source

You can pass multiple expressions (-e) to sed:

sed \
    -e 's/\x00/\x20/g' \
    -e 's/\xB0/\x20/g' \
    -e 's/\x21/\x40/g' \
    -e 's/[\x80-\xFF]/\x20/g' \
    -e 's/\x22/\x43/g' File_In > File_out
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download