sed替换为十六进制

tou*_*ker 4 linux grep sed

UTF-8文件test.txt:

AAAAAAAAAAAAAA
Run Code Online (Sandbox Code Playgroud)

十六进制是

41 41 41 41 41 41 41 41 41 41
Run Code Online (Sandbox Code Playgroud)

sed s/A/B/g test.txt 作品

sed s/\x41/B/g test.txt 不起作用

有些字符是不可打印的,所以我必须使用它们的十六进制,A这只是一个例子.

Kar*_*ath 11

shell预处理它,使用单引号.

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

echo -e \x41   # x41
echo -e '\x41' # A
Run Code Online (Sandbox Code Playgroud)