1

I was wondering how I could retrieve bytes from a files given an offset and a length.

I came to the following line : hexdump -n 4 -s 0x11C myFile

I get the following : Not good enough, I don't need the offset.

000011c 00 00 8c d0

Second try :

hexdump -n 4 -s 0x11C -e '"%x\n"' myFile

I get the following : better but wrong endianness.

d08c0000

So how can I do it ? I know I could parse it with sed, but isn't there a «cleaner» solution that that ?

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134

1 Answers1

2
hexdump -n 4 -s 0x11C -e '4/1 "%x " "\n"' myFile

(My version of hexdump does not produce one-byte hex output as in your first example. Did you use some other command option?)

rici
  • 234,347
  • 28
  • 237
  • 341
  • I'm on OSX so it's a BSD hexdump, maybe that's why. Thanx for your answer, that'll do it ! Actually I don't need the space, so I removed it. – Matthieu Riegler Oct 06 '13 at 23:57
  • @MatthieuRiegler: Could be. I don't see anything in the docs which would explain that, though. My format should work, though. (I hope.) – rici Oct 07 '13 at 00:01