2

I have a 588Ko file, and I want to extract bytes from 0x7E8D6 to 0x8AD5D. I tried :
dd if=file of=result bs=50311 count=1 skip=518358

  • 50311 stands for 0x8AD5D - 0x7E8D6
  • 518358 stands for 0x7E8D6 (from where I want to cut)

dd tells me that it can't skip to the specified offset. What can I do? Is there any other utility to do it?

Nark
  • 185

2 Answers2

5

Use dd to extract a precise portion of a file?

Lets adjust your syntax a little bit.

bs=1

Set the block size to one because of any count or skip you want to be in single blocks or bytes.

skip=518358

Skip this many blocks or bytes at the beginning of the stream.

count=50311

Copy this many blocks or bytes from the stream.

dd if=/path/file of=/path/result bs=1 count=50311 skip=518358

jc__
  • 2,605
3

skip and count are both expressed in blocks. You're asking to skip 518358 × 50311 bytes.

dd can let errors go undetected, so it's best avoided anyway.

With most Unix variants (including BusyBox but not OpenSBD), you can pass a number of bytes to head and tail. Just remember that tail counts from 1.

<file tail -c "$((0x7E8D6 + 1))" | head -c "$((0x8AD5D - 0x7E8D6))" >result