Linux 如何在没有行号或 ASCII 表的情况下仅打印来自 hexdump 的十六进制值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15553493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:30:32  来源:igfitidea点击:

How to print only the hex values from hexdump without line numbers or ASCII table?

linuxbashshellhexdump

提问by 0x90

following Convert decimal to hexadecimal in UNIX shell script

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

I am trying to print only the hex valuesfrom hexdump, i.e. don't print the lines numbers and the ASCII table.

我试图只打印hex valuesfrom hexdump,即不打印行号和 ASCII 表。

But the following command line doesn't print anything:

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

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

采纳答案by chepner

You can specify the exact format that you want hexdumpto use for output, but it's a bit tricky. Here's the default output, minus the file offsets:

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

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

(To me, it looks like this would produce an extra trailing space at the end of each line, but for some reason it doesn't.)

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

回答by glenn Hymanman

First of all, remove -Cwhich is emitting the ascii information.

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

Then you could drop the offset with

然后你可以删除偏移量

hexdump -n 50 -s 10 file.bin | cut -c 9-

回答by twalberg

As an alternative, consider using xxd -p file.bin.

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

回答by 0x90

Using xxdis better for this job:

使用xxd更适合这项工作:

xxd -p -l 50 -seek 10 file.bin

From man xxd:

来自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.