Skip to main content
with the edit by ilkkachu, the argument to head -c is now the length of the segment to extract, not the end position
Source Link

Try this:

tail -c +$FROM file.dat | head -c $TO$LENGTH > file1.dat

Just assign FROM and TOLENGTH as you need. Note that the numbering for tail is one-based and e.g. tail -c +4 means to start at the fourth byte, that is to skip the first three bytes.

As an example:

$ printf 'abcdefghijklmnopqrstuvwxyz\n' > test.txt
$ tail -c +4 test.txt | head -c 6; echo
defghi

Try this:

tail -c +$FROM file.dat | head -c $TO > file1.dat

Just assign FROM and TO as you need. Note that the numbering for tail is one-based and e.g. tail -c +4 means to start at the fourth byte, that is to skip the first three bytes.

As an example:

$ printf 'abcdefghijklmnopqrstuvwxyz\n' > test.txt
$ tail -c +4 test.txt | head -c 6; echo
defghi

Try this:

tail -c +$FROM file.dat | head -c $LENGTH > file1.dat

Just assign FROM and LENGTH as you need. Note that the numbering for tail is one-based and e.g. tail -c +4 means to start at the fourth byte, that is to skip the first three bytes.

As an example:

$ printf 'abcdefghijklmnopqrstuvwxyz\n' > test.txt
$ tail -c +4 test.txt | head -c 6; echo
defghi
added 284 characters in body
Source Link
ilkkachu
  • 148.1k
  • 16
  • 268
  • 441

Try this:

headtail -c $TO+$FROM file.dat | tailhead -c +$FROM$TO > file1.dat

Just assign FROM and TO as you need. Note that the numbering for tail is one-based and e.g. tail -c +4 means to start at the fourth byte, that is to skip the first three bytes.

As an example:

$ printf 'abcdefghijklmnopqrstuvwxyz\n' > test.txt
$ tail -c +4 test.txt | head -c 6; echo
defghi

Try this:

head -c $TO file.dat | tail -c +$FROM > file1.dat

Just assign FROM and TO as you need.

Try this:

tail -c +$FROM file.dat | head -c $TO > file1.dat

Just assign FROM and TO as you need. Note that the numbering for tail is one-based and e.g. tail -c +4 means to start at the fourth byte, that is to skip the first three bytes.

As an example:

$ printf 'abcdefghijklmnopqrstuvwxyz\n' > test.txt
$ tail -c +4 test.txt | head -c 6; echo
defghi
Source Link
White Owl
  • 5.3k
  • 1
  • 9
  • 16

Try this:

head -c $TO file.dat | tail -c +$FROM > file1.dat

Just assign FROM and TO as you need.