我如何转储“纯”且简单的二进制位序列?
例如,我有这个:
0000000: 10001001 01010000 01001110 01000111 00001101 00001010 .PNG..
0000006: 00011010 00001010 00000000 00000000 00000000 00001101 ......
000000c: 01001001 01001000 01000100 01010010 00000000 00000000 IHDR..
0000012: 00000010 01011000 00000000 00000000 00000001 10010000 .X....
0000018: 00001000 00000010 00000000 00000000 00000000 11111101 ......
000001e: 01010111 10001001 11001111 00000000 00000000 00000000 W.....
0000024: 00000111 01110100 01001001 01001101 01000101 00000111 .tIME.
左边的行号和右边的 ASCII 对我来说是个问题。我试过用这个来删除它:
xxd -b /root/Desktop/image.png | sed -r "s/\d32{3,}.*//g" | sed "s/.*://" | sed "s/\d32//g"
但是,我没有成功:
100010010101000001001110010001110000110100001010.PNG..
000110100000101000000000000000000000000000001101......
010010010100100001000100010100100000000000000000IHDR..
000000100101100000000000000000000000000110010000.X....
000010000000001000000000000000000000000011111101......
010101111000100111001111000000000000000000000000W.....
000001110111010001001001010011010100010100000111.tIME.
是否有像“xxd”或“hexdump”这样的工具或其他东西可以从文件中生成干净的二进制序列?
例如,
01010101000100100100010100100010000010101010101010101001011
10101010101010100100101010101010100000010001000100001000000
答案1
将输出解析为您想要的格式非常简单:
xxd -b /root/Desktop/image.png | cut -d: -f 2 | sed 's/ .*//; s/ //g'
将cut
删除行号,并且 sed 将首先删除最后一列(s/ .*//
将删除两个连续空格后的所有内容),然后删除所有单个空格。
您还可以使用awk
:
xxd -b ~/a.png | awk '{print $2$3$4$5$6$7}'
或者 Perl:
xxd -b ~/a.png | head -1 | perl -lane 'print join "",@F[1..6]'
或者核心工具:
xxd -b ~/a.png | cut -d" " -f2-7 | tr -d ' '