How can I change the number of columns printed by hexdump
from the default 16 (to 21)?
Or where can I find the place to change the default format string used in hexdump
in order to modify the number used there?
It seems that the default format is obtained thus:
hexdump -e '"%07.7_Ax\n"' -e '"%07.7_ax " 8/2 "%04x " "\n"'
From man hexdump
:
Implement the -x option:
"%07.7_Ax\n"
"%07.7_ax " 8/2 "%04x " "\n"
If you want to understand hexdump
's format, you'll have to read the manual, but here's a short walkthrough of the previous format:
The first part %07.7_Ax\n
is the part that displays the last line that only contains the offset. Per the manual:
_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.
For the second: we now understand the "%07.7_ax "
part. The 8/2
means 8 iterations and 2 bytes for the following, namely, "%04x "
. Finally, after these, we have a newline: "\n"
.
I'm not really sure how you want your 21 bytes. Maybe this would do:
hexdump -e '"%07.7_Ax\n"' -e '"%07.7_ax " 21/1 "%02x " "\n"'
And you know how to get rid of the offset, if needed:
hexdump -e '21/1 "%02x " "\n"'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With