Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed replace with hex

Tags:

linux

grep

sed

UTF-8 file test.txt:

AAAAAAAAAAAAAA

hex is

41 41 41 41 41 41 41 41 41 41

sed s/A/B/g test.txt works

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

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

like image 550
toughtalker Avatar asked Dec 06 '22 20:12

toughtalker


2 Answers

the shell preprocesses it, use single quotes.

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

echo -e \x41   # x41
echo -e '\x41' # A
like image 167
Karoly Horvath Avatar answered Dec 09 '22 08:12

Karoly Horvath


If you only want to replace individual characters, you should be able to use tr with octal escapes like this:

tr '\101' B
like image 33
chrisdowney Avatar answered Dec 09 '22 08:12

chrisdowney