【问题标题】:How to print only the hex values from hexdump without the line numbers or the ASCII table? [duplicate]如何仅打印 hexdump 中的十六进制值,而不打印行号或 ASCII 表? [复制]
【发布时间】:2013-03-11 07:33:42
【问题描述】:

关注Convert decimal to hexadecimal in UNIX shell script

我正在尝试仅打印来自 hexdumphex values,即不打印行号和 ASCII 表。

但是下面的命令行不打印任何东西:

hexdump -n 50 -Cs 10 file.bin |  awk '{for(i=NF-17; i>2; --i) print $i}'

【问题讨论】:

标签: linux bash shell hexdump


【解决方案1】:

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

然后你可以用

删除偏移量
hexdump -n 50 -s 10 file.bin | cut -c 9-

【讨论】:

  • 它似乎工作但改变了字节序...
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

    • @andsens hexdump 在busybox 中,因此可以嵌入,而xxd 不是:Ь
    【解决方案4】:

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

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

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

    【讨论】:

    • 太棒了!!这个答案对我有用!但我认为最好也有-C 选项。如果您添加cut -c 9- | head -n 1,您的输出将仅显示十六进制数字。
    • This blog entry 展示了更多示例如何修改hexdump 的输出格式。
    • 添加-v 以列出每一行,而不是与* 压缩相同的行
    猜你喜欢
    • 2012-11-12
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多