Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to split a binary file into smaller files based on pattern 'xÚ' (it's 78 DA in hexadecimal), so when there's an 'xÚ' in the file the splitter script splits and pastes the content into a new file until another 'xÚ' can be found. The newly created files should start as 'xÚ'.

FreeBSD AWK, GREP, sh preferred.

share|improve this question

1 Answer 1

EDIT:

Ok here is the cleanup of that mess:

awk 'BEGIN { RS=""; FS=/\x78\xda/ } { for (i = 1; i <= NF; i++) print $i > i }' YOUR_BIN_FILE

Empty RS could still be causing unexpected results as it makes awk seperate records at blank lines. In fact it is difficult to circumvent a splitup of a file into records. One way to solve this is to set the record seperator to some pattern that is not present in the file. Another way would be to seperate records by 78da and process every record.

share|improve this answer
3  
You could echo "78da$i" | xxd .... You don't need cat: xxd -ps -c $FILESIZE $MY_BINARY. You may need to set RS to null in awk to keep it from splitting on \x0a: BEGIN {RS=""}. You can make it easier to reassemble the files if you use printf to format the filenames: outfile=$(printf "outfile.%04d" $COUNT) (filenames will look like "outfile.0001"). You don't need redirection for output from xxd -r: xxd -r -ps -c $FILESIZE - $outfile. –  Dennis Williamson Aug 10 '10 at 23:49
    
I like my cat ;) I needed the hint to empty RS, thanks! I removed the mess that caused eyes bleeding. –  matthias krull Aug 11 '10 at 8:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.