参考 Convert decimal to hexadecimal in UNIX shell script,我正在尝试从hexdump
中仅打印出16进制值
,即不要打印行号和ASCII表。
但是以下命令没有输出:
hexdump -n 50 -Cs 10 file.bin | awk '{for(i=NF-17; i>2; --i) print $i}'
参考 Convert decimal to hexadecimal in UNIX shell script,我正在尝试从hexdump
中仅打印出16进制值
,即不要打印行号和ASCII表。
但是以下命令没有输出:
hexdump -n 50 -Cs 10 file.bin | awk '{for(i=NF-17; i>2; --i) print $i}'
使用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.
hexdump
工具包含在 busybox
中,因此可用于嵌入式系统,而 xxd
则不行。 - Hi-Angel您可以指定hexdump
输出的确切格式,但这有点棘手。以下是默认输出(不包括文件偏移量):
hexdump -e '16/1 "%02x " "\n"' file.bin
对我来说,看起来这会在每行末尾产生额外的空格,但出于某种原因它没有。
-C
选项更好。如果你再加上cut -c 9- | head -n 1
,你的输出将只显示十六进制数字。 - Kyrolhexdump
输出格式的示例。链接:https://blog.senpaisilver.com/linux/formatting-hexdumps-output/ - Matthias Braun-v
参数,这样每一行都会被列出来,不会使用*
将相同的行压缩。 - dagelfxxd -p file.bin
。首先,删除发射ascii信息的-C
。
然后,您可以使用以下命令删除偏移量:
hexdump -n 50 -s 10 file.bin | cut -c 9-