Split file into chunks of low & high byte

Hi guys,

i have a question about spliting a binary file into 2 chunks.
First chunk with all high bytes and the second one with all low bytes.

What unix tools can i use? And how can this be performed?
I looked in manpages of split and dd but this does not help.

Thanks

Can you specify what exactly you mean by low and high byte? You want to split alternating bytes in a file into two files? If so, which is the high and which is the low? Is it big endian or little endian. Some sample data and sample desired output is worth 2^10 words :wink:

Alister

---------- Post updated at 01:42 PM ---------- Previous update was at 12:05 PM ----------

In case it's of any use, I went ahead and whipped something up since the problem piqued my interest:

od -An -vtd1 file | tr -cs '0-9' '\n' | awk 'NF{printf("%c",$0) > (++i%2?"hi":"lo")}'

Sample run on using a binary file i created which contains 64 bytes whose values increase from 0 (null byte not a problem) to 63 (treating this as bigendian, with the most significant byte first):

$ od -td1 bin 
0000000     0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
0000020    16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31
0000040    32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47
0000060    48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63
0000100

$ od -An -vtd1 bin | tr -cs '0-9' '\n' | awk 'NF{printf("%c",$0) > (++i%2?"hi":"lo")}'

$ od -td1 hi
0000000     0   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30
0000020    32  34  36  38  40  42  44  46  48  50  52  54  56  58  60  62
0000040

$ od -td1 lo
0000000     1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31
0000020    33  35  37  39  41  43  45  47  49  51  53  55  57  59  61  63
0000040

While this may not be an efficient solution (bytes are converted to lines of numeric text which are then converted back to bytes and output one char at a time), it is simple, compact, and should give the desired result. :wink:

Regards,
Alister

1 Like

Hi alister,

thank you for your reply.

Its just what i needed. I will test it now.

Regards
basta