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
How to print only the hex values from hexdump without line numbers or ASCII table?
提问by 0x90
following Convert decimal to hexadecimal in UNIX shell script
I am trying to print only the hex values
from hexdump
, i.e. don't print the lines numbers and the ASCII table.
我试图只打印hex values
from 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 hexdump
to 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 -C
which 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 xxd
is 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.