如何仅打印 hexdump 中的十六进制值,而不打印行号或 ASCII 表? [重复]

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

以下在 UNIX shell 脚本中将十进制转换为十六进制

我试图仅打印

hex values
中的
hexdump
,即不打印行号和 ASCII 表。

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

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

使用

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.

68
投票

您可以指定您想要

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

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

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


30
投票

作为替代方案,请考虑使用

xxd -p file.bin


3
投票

首先,删除发出 ascii 信息的

-C

然后你可以用

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