Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 2
    Are parameters here zero based and TO exclusive and FROM inclusive? Commented Mar 27, 2023 at 19:32
  • 2
    @Dims reading man head and man tail you can see that head -c 5 would give you the first five bytes of the source, and piping to tail -c +3 (or indeed head -c 3) would give you the first three bytes of that Commented Mar 27, 2023 at 19:40
  • @roaima You got it wrong with the tail. use -c +NUM to output starting with byte NUM. It will give you the last characters, starting with 3. Commented Mar 28, 2023 at 16:20
  • 4
    If $FROM can be large, it's probably more efficient to do tail -c +$FROM file.dat | head -c $LENGTH. That way tail can seek past the first $FROM bytes and start reading from there (and stop when it gets a SIGPIPE after head stops reading more data). Commented Mar 28, 2023 at 22:30
  • @IlmariKaronen, yes, that's a good point. At least GNU tail does seek (no surprise), Busybox didn't. Commented Mar 29, 2023 at 10:26