I have binary data which I review by xxd -ps in hex format. I notice that the byte distance is 48300 (=805*60) bytes between two headers where the separator is fafafafa. There is the beginning of the file which should be skipped. Example hex data where 48300 bytes between headers fafafafa which you can get here called data26.6.2015.txt where three headers and its nearly equivalent binary here called test_27.6.2015.bin which has only first two headers. In both files, the data of last header is not of complete length; otherwise, you can assume that the byte offset is fixed i.e. the length of data between headers.Pseudocode of algorithmlook header end positionlook first two header positions and set the difference of these positions (d2 - d1) the distance between events; this event length is the fixed (777)split data by byte position (777) - TODO should I split binary format or as xxd -ps converted data? by byte position (777)I can convert data back to binary by xxd -r like xxd -ps | split and store | xxd -r but I am still unsure if this is necessary. In which stage can you split binary data? Only in xxd -ps converted format or as binary data. If splitting in xxd -ps converted format, I think for loop is to only way then go through the file. Possible tools for splitting csplit, split, ..., not sure. However, I am uncertain. Output from grep (ggrep is gnu grep) on the hex data$ xxd -ps r328.raw  | ggrep -b -a -o -P 'fafa' | head49393:fafa49397:fafa98502:fafa98506:fafa147611:fafa147615:fafa196720:fafa196725:fafa245830:fafa245834:fafawhile doing the similar grep in the binary file giving emptyline only as an output. $ ggrep -b -a -o '\xfa' r328.raw DocumentationDocumentation given to me is found here and here as a picture the general SRS data format:In which stage can you split binary data (as binary data or as xxd -ps converted data)?
Split binary data of fixed byte offset by byte position?
grep;binary;split;xxd
Outputs to great meuh's answer where he used data data26.6.2015.txt.#1$ cat 27.6.2015_1.sh && sh 27.6.2015_1.sh xxd -r -p <data26.6.2015.txt >/tmp/f1size=$(stat -c '%s' /tmp/f1)pat=$(echo -e '\xfa\xfa\xfa\xfa')set -- 0 $(ggrep -b -a -o $pat /tmp/f1 | sed 's/:.*//') $sizei=2while [ $# -ge 2 ]do start=$1 end=$2   let count=$end-$start   dd bs=1 count=$count skip=$start </tmp/f1 >/tmp/f$i   let i=i+1   shiftdone72900+0 records in72900+0 records out72900 bytes (73 kB) copied, 0.160722 s, 454 kB/s#2$ cat 27.6.2015_2.sh && sh 27.6.2015_2.sh xxd -r -p <data26.6.2015.txt >/tmp/f1size=$(stat -c '%s' /tmp/f1)set -- 0 $(ggrep -b -a -o -P '\xfa\xfa\xfa\xfa' /tmp/f1 | sed 's/:.*//') $sizei=2while [ $# -ge 2 ]do start=$1 end=$2   let count=$end-$start   dd bs=1 count=$count skip=$start </tmp/f1 >/tmp/f$i   let i=i+1   shiftdone72900+0 records in72900+0 records out72900 bytes (73 kB) copied, 0.147935 s, 493 kB/s#3$ cat 27.6.2015_3.sh && sh 27.6.2015_3.sh xxd -r -p <data26.6.2015.txt >r328.rawtr -d '\n' <data26.6.2015.txt >f1let size2=2*$(stat -c '%s' f1)set -- 0 $(ggrep -b -a -o -P 'fafafafa' f1 | sed 's/:.*//') $size2i=2while [ $# -ge 2 ]do  let start=$1/2    let end=$2/2    let count=$end-$start    dd bs=1 count=$count skip=$start <r328.raw  >f$i    let i=i+1    shiftdone24292+0 records in24292+0 records out24292 bytes (24 kB) copied, 0.088345 s, 275 kB/s24152+0 records in24152+0 records out24152 bytes (24 kB) copied, 0.061246 s, 394 kB/s24152+0 records in24152+0 records out24152 bytes (24 kB) copied, 0.058611 s, 412 kB/s304+0 records in304+0 records out304 bytes (304 B) copied, 0.001239 s, 245 kB/sOutput is one hex file and 4 binary files:$ less f1$ less f2f2 may be a binary file.  See it anyway? $ less f3f3 may be a binary file.  See it anyway? $ less f4f4 may be a binary file.  See it anyway? $ less f5f5 may be a binary file.  See it anyway? There should be only 3 files which have fafafafa because I only gave three headers in file data26.6.2015.txt where the content of last header is a stubb. Outputs in f2-f5:$ xxd -ps f2 |head -n348000000fe5a1eda480000000d00030001000000cd010000010000000000000000000000000000000000000000000000000000000100000001000000ffffffff57ea5e5580510b0048000000fe5a1eda480000000d0003000100$ xxd -ps f3 |head -n3fafafafa585e0000fe5a1eda480000000d00030007000000cd010000020000000000000002000000000000800000000000000000000000000000000001000000ffffffff72ea5e55b2eb0900105e000016000000010000000000$ xxd -ps f4 |head -n3fafafafa585e0000fe5a1eda480000000d00030007000000cd010000030000000000000002000000000000800000000000000000000000000000000001000000ffffffff72ea5e55f2ef0900105e000016000000010000000000$ xxd -ps f5 |head -n3fafafafa585e0000fe5a1eda480000000d00030007000000cd010000040000000000000002000000000000800000000000000000000000000000000001000000ffffffff72ea5e55a9f10900105e000016000000010000000000where f1 is the whole datafile data26.6.2015.txt (not necessary to include)f2 is the file header i.e. very beginning of the file data26.6.2015.txt until the first header fafafafa (not necessary to include)f3 is the first header, correct!f4 is the second header, correct!f5 is the third header, correct! 