简体   繁体   中英

sed replace with hex

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.

the shell preprocesses it, use single quotes.

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

echo -e \x41   # x41
echo -e '\x41' # A

如果你只想替换单个字符,你应该能够使用带有八进制转义符的tr,如下所示:

tr '\101' B

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM