I am writing a bash script that should get the header (first 10 bytes) of a file, and then in another section get everything except the first 10 bytes. These are binaries and are likely to have \0 and \n for the first 10 bytes. Most utilities seem to work with ASCII files. What is a good way to achieve this?
\0
\n
To get the first 10 bytes, as already noted:
head -c 10
To get everything except the first 10 bytes (at least with GNU tail ):
tail
tail -c+11
You can use the dd to copy an arbitrary number of bytes from a binary file.
dd
dd if=infile of=outfile1 bs=10 count=1 dd if=infile of=outfile2 bs=10 skip=1
head -c 10 does the right thing here.