用于检查十六进制语法的sed

时间:2013-05-01 13:03:35

标签: sed hex

我有关注文件:

cat 123
# carriers mask for G1,G2 (96 - 168 kHz)
#       91, 4, {0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF} \
# carriers mask for G3 (96 - 288 kHz)
#       91, 4, {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF} \

并想检查图形括号中是否有正确的字符串

我写了下面的表达式(检查每个12个十六进制表达式是否都有正确的语法)

sed -r -n '/^.*91, 4, {\(0x[0-9A-F],\)\{11\}0x[0-9A-F]}.*/p' 123
sed: bad regex '^.*91, 4, {\(0x[0-9A-F],\)\{11\}0x[0-9A-F]}.*': Invalid content of \{\}

我试图以其他方式表达

sed -rne '/^.*91, 4, {0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F]}.*/ {p}' 123
sed: bad regex '^.*91, 4, {0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F],0x[0-9A-F]}.*': Invalid content of \{\}

有谁可以说明我的错误在哪里?

提前谢谢。

1 个答案:

答案 0 :(得分:1)

应该没有-r选项,而您只检查个位数。你可以尝试类似的东西:

sed -n '/91, 4, {\(0x[0-9A-F][0-9A-F],\)\{11\}0x[0-9A-F][0-9A-F]}/p' file