toughtalker toughtalker - 1 year ago 167
Linux Question

sed replace with hex

UTF-8 file test.txt:


hex is

41 41 41 41 41 41 41 41 41 41

sed s/A/B/g test.txt

sed s/\x41/B/g test.txt
does not work

Some characters are unprintable so I must use their hex,
is just an example.

Answer Source

the shell preprocesses it, use single quotes.

sed 's/\x41/B/g' test.txt

echo -e \x41   # x41
echo -e '\x41' # A
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download