如何更改`hexdump`打印的列数?

11

我该如何将hexdump默认打印的列数从16更改为21?

或者在哪里可以找到更改hexdump中使用的默认格式字符串的地方,以便修改其中使用的数字?


7
您可以尝试使用此命令:hexdump -e '21/1 "%02x " "\n"' - gniourf_gniourf
@gniourf_gniourf 它正常工作了!谢谢。 - Ilya Smagin
请找到一个回答,其中还包含有关默认格式的信息。 - gniourf_gniourf
1个回答

13

看起来,默认格式是这样获得的:

hexdump -e '"%07.7_Ax\n"' -e '"%07.7_ax " 8/2 "%04x " "\n"'

来自 man hexdump 的描述:

 Implement the -x option:

       "%07.7_Ax\n"
       "%07.7_ax  " 8/2 "%04x " "\n"

如果您想理解hexdump的格式,您需要阅读手册,但以下是对先前格式的简短说明:

  • 第一部分%07.7_Ax\n是显示仅包含偏移量的最后一行的部分。根据手册:

   _a[dox]     Display the input offset, cumulative across input files, of the
               next byte to be displayed.  The appended characters d, o, and x
               specify the display base as decimal, octal or hexadecimal
               respectively.

   _A[dox]     Identical to the _a conversion string except that it is only
               performed once, when all of the input data has been processed.
  • 第二个部分:我们现在理解了"%07.7_ax "这一部分。其中的8/2表示8次迭代,每次需要读取两个字节,也就是"%04x "。最后,在所有这些之后,我们有一个换行符:"\n"

  • 我不太确定您希望的21字节是什么。也许这样就可以了:

    hexdump -e '"%07.7_Ax\n"' -e '"%07.7_ax " 21/1 "%02x " "\n"'
    

    如果需要,您知道如何消除偏移:

    hexdump -e '21/1 "%02x " "\n"'
    

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接