This question already has an answer here:
这个问题在这里已有答案:
- How to create a hex dump of file containing only the hex characters without spaces in bash? 5 answers
- 如何创建一个只包含bash中没有空格的十六进制字符的文件的十六进制转储? 5个答案
following Convert decimal to hexadecimal in UNIX shell script
在UNIX shell脚本中将以下内容转换为十六进制
I am trying to print only the hex values
from hexdump
, i.e. don't print the lines numbers and the ASCII table.
我试图只打印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}'
4 个解决方案
#1
28
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.)
(对我来说,看起来这会在每一行的末尾产生额外的尾随空格,但由于某种原因,它不会。)
#2
40
Using xxd
is better for this job:
使用xxd对于这项工作更好:
xxd -p -l 50 -seek 10 file.bin
From man xxd
:
来自man xxd:
-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.
#3
18
As an alternative, consider using xxd -p file.bin
.
作为替代方案,请考虑使用xxd -p file.bin。
#4
4
First of all, remove -C
which is emitting the ascii information.
首先,删除发出ascii信息的-C。
Then you could drop the offset with
然后你可以删除偏移量
hexdump -n 50 -s 10 file.bin | cut -c 9-
#1
28
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.)
(对我来说,看起来这会在每一行的末尾产生额外的尾随空格,但由于某种原因,它不会。)
#2
40
Using xxd
is better for this job:
使用xxd对于这项工作更好:
xxd -p -l 50 -seek 10 file.bin
From man xxd
:
来自man xxd:
-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.
#3
18
As an alternative, consider using xxd -p file.bin
.
作为替代方案,请考虑使用xxd -p file.bin。
#4
4
First of all, remove -C
which is emitting the ascii information.
首先,删除发出ascii信息的-C。
Then you could drop the offset with
然后你可以删除偏移量
hexdump -n 50 -s 10 file.bin | cut -c 9-