I'm trying to create a hexdump of 8 hexadecimal numbers per line. I'm using the following command
hexdump -v -e '"\t" 7/1 "0x%02x, " 1/1 "0x%02x,\n"' booter_load_tu102.bin
This is supposed to output a tab, 7 hex numbers separate by a comma and a blank space, and then a final 8th number with a comma and end-of-line. However, when I run this command, I get something not quite right:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00,
Why is there no blank space between the 7th and 8th number? If I modify the command like this:
hexdump -v -e '"\t" 7/1 "0x%02x, " 1/1 " 0x%02x,\n"' booter_load_tu102.bin
(inserting a blank space before the final "0x%02x,") it works:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Why is hexdump not inserting a blank space after the 7th number?
Seems a single trailing whitespace at the end of a format group is discarded. I guess for convenience reasons.
That makes your expression easier, because you can use an easier format string, consume and format all 8 bytes the same way, append a line break and still have the desired output:
hexdump -v -e '"\t" 8/1 "0x%02x, " "\n"' booter_load_tu102.bin
worked fine for me.