重新创建 hexdump -C 格式作为 -e 参数。

huangapple go评论79阅读模式
英文:

Recreate hexdump -C format as -e argument

问题

我正在尝试重新创建`hexdump -C`将输出的格式,即

00000000 50 4b 03 04 2d 00 04 00 08 00 16 b5 ea 56 99 f1 |PK..-........V..|
00000010 ef 29 ff ff ff ff ff ff ff ff 0f 00 30 00 6e 61 |.)..........0.na|


我得到了类似于以下的结果

hexdump -n 200 -e '16/1 "%02x "' -e '"|" ' -e '16/1 "%_p"|"\n"' file.zip


产生

50 4b 03 04 2d 00 04 00 08 00 16 b5 ea 56 99 f1 |PK..-........V..|
ef 29 ff ff ff ff ff ff ff ff 0f 00 30 00 6e 61 |.)..........0.na|


但是如何在每8个字节后添加额外的空格和文件中的偏移量呢?
英文:

I am trying to recreate the format that hexdump -C will output, namely

00000000  50 4b 03 04 2d 00 04 00  08 00 16 b5 ea 56 99 f1  |PK..-........V..|
00000010  ef 29 ff ff ff ff ff ff  ff ff 0f 00 30 00 6e 61  |.)..........0.na|

I'm arriving at something like

hexdump -n 200 -e '16/1 "%02x ""\t"" "' -e '"|"' -e '16/1 "%_p""|\n"' file.zip

giving

50 4b 03 04 2d 00 04 00 08 00 16 b5 ea 56 99 f1	 |PK..-........V..|
ef 29 ff ff ff ff ff ff ff ff 0f 00 30 00 6e 61	 |.)..........0.na|

but how do I add the extra space every 8 bytes and the offset in the file?

答案1

得分: 1

好的,这是翻译好的部分:

"OK, found it: We can create groups by repeating format specifications inside the same -e block, and we output the offset with %10_ax."

"好的,找到了:我们可以通过在相同的 -e 块内重复使用格式规范来创建分组,并且我们使用 %10_ax 输出偏移量。"

"For double width (32 bytes), my whole commandline now looks like:"

"对于双宽度(32字节),我的整个命令行现在看起来像是:"

hexdump -n 200 -e '1/1 "%10_ax""   "' -e '8/1 "%02x "' ' 8/1 "%02x "' ' 8/1 "%02x "' ' 8/1 "%02x "' '|' -e '32/1 "%_p"'|'\n"'
hexdump -n 200 -e '1/1 "%10_ax""   "' -e '8/1 "%02x "' ' 8/1 "%02x "' ' 8/1 "%02x "' ' 8/1 "%02x "' '|' -e '32/1 "%_p"'|'\n"'

"file.zip"

"file.zip"

英文:

OK, found it: We can create groups by repeating format specifications inside the same -e block, and we output the offset with %10_ax.

For double width (32 bytes), my whole commandline now looks like:

hexdump -n 200 -e '1/1 "%10_ax""   "' -e '8/1 "%02x ""  " 8/1 "%02x ""  " 8/1 "%02x ""  " 8/1 "%02x ""  |"' -e '32/1 "%_p""|\n"' file.zip

huangapple
  • 本文由 发表于 2023年7月13日 22:12:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680352.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定