如何只打印hexdump中没有行号或ASCII表的十六进制值? [重复]

问题描述 投票:20回答:4

关注Convert decimal to hexadecimal in UNIX shell script

我试图只打印来自hex valueshexdump,即不打印行号和ASCII表。

但是以下命令行不会打印任何内容:

hexdump -n 50 -Cs 10 file.bin |  awk '{for(i=NF-17; i>2; --i) print $i}'
linux bash shell hexdump
4个回答
37
投票

您可以指定hexdump用于输出的确切格式,但这有点棘手。这是默认输出,减去文件偏移量:

hexdump -e '16/1 "%02x " "\n"' file.bin

(对我来说,看起来这会在每一行的末尾产生一个额外的尾随空格,但由于某种原因,它不会。)


51
投票

使用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.

19
投票

作为替代方案,请考虑使用xxd -p file.bin


4
投票

首先,删除发出ascii信息的-C

然后你可以删除偏移量

hexdump -n 50 -s 10 file.bin | cut -c 9-
© www.soinside.com 2019 - 2024. All rights reserved.