0

please help to find a way to convert the data as follows: I read from disk using dd utility

dd if=/dev/sdb skip=8388608 count=560 iflag=skip_bytes,count_bytes |hexdump -C

and I am getting

000001a0 00 00 00 00 cf 4c 79 ce 00 00 00 00 00 00 00 00 |.....Ly.........|

but I would like to get :

000001a0 ce794ccf00000000 0000000000000000 |.....Ly.........|

I do not have to use hexdump, any other tool can also do the trick. Thank you.

2
  • Please clarify some more: You want each set of 8 bytes shown in reverse order but the normal character display stay untouched?
    – FelixJN
    Commented Feb 10, 2022 at 9:53
  • Exactly. I got the answer below. Thank you.
    – markmi
    Commented Feb 10, 2022 at 12:05

2 Answers 2

1

The reversed order of hex bytes is due to little-endian processing of single bytes.

hexdump does not seem to allow for 64-bit values, but od (octal dump) does. Replace the call to hexdump with:

od -t x8z

which outputs 64-bit hex long-words, and ASCII. The ASCII is bracketed by >...< which should be easy to skip.

1
  • Great answer, will do this. Thank you.
    – markmi
    Commented Feb 10, 2022 at 12:05
0

hexdump's output is fully customisable even if the syntax may seem a bit obscure at first:

$ seq 10 | hexdump -C
00000000  31 0a 32 0a 33 0a 34 0a  35 0a 36 0a 37 0a 38 0a  |1.2.3.4.5.6.7.8.|
00000010  39 0a 31 30 0a                                    |9.10.|
00000015
$ seq 10 | hexdump -e '"%08.8_ax " 2/8 " %016x"' -e '"  |" 16 "%_p" "|\n"' -e '"%08.8_Ax\n"'
00000000  0a340a330a320a31 0a380a370a360a35  |1.2.3.4.5.6.7.8.|
00000010  0000000a30310a39                   |9.10.|
00000015

The byte order (little endian above) for those 64 bit integers depends on your system's computer architecture / C compiler.

Note the 0 padding to satisfy the missing bytes for the last number above.

Note that rather than using dd's skip and count, you can use hexdump's -s and -n.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .