这个问题在这里已有答案:
关注Convert decimal to hexadecimal in UNIX shell script
我试图只打印来自hex values
的hexdump
,即不打印行号和ASCII表。
但是以下命令行不会打印任何内容:
hexdump -n 50 -Cs 10 file.bin | awk '{for(i=NF-17; i>2; --i) print $i}'
您可以指定hexdump
用于输出的确切格式,但这有点棘手。这是默认输出,减去文件偏移量:
hexdump -e '16/1 "%02x " "\n"' file.bin
(对我来说,看起来这会在每一行的末尾产生一个额外的尾随空格,但由于某种原因,它不会。)
使用xxd
对这项工作更好:
xxd -p -l 50 -seek 10 file.bin
来自man xxd
:
xxd - make a hexdump or do the reverse.
-p | -ps | -postscript | -plain
output in postscript continuous hexdump style. Also known as plain hexdump style.
-l len | -len len
stop after writing <len> octets.
-seek offset
When used after -r: revert with <offset> added to file positions found in hexdump.
作为替代方案,请考虑使用xxd -p file.bin
。
首先,删除发出ascii信息的-C
。
然后你可以删除偏移量
hexdump -n 50 -s 10 file.bin | cut -c 9-