英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论