我有一个二进制文件,我使用hexdump和几个awk和sed命令转换成一个常规文件.输出文件看起来像这样 –
$cat temp 3d3d01f87347545002f1d5b2be4ee4d700010100018000cc57e5820000000000000000000 000000087d3f513000000000000000000000000000000000001001001010f000000000026 58783100b354c52658783100b43d3d0000ad6413400103231665f301010b9130194899f2f fffffffffff02007c00dc015800a040402802f1d5b2b8ca5674504f433031000000000004 6363070000000000000000000000000065450000b4fb6b4000393d3d1116cdcc57e58287d 3f55285a1084b
临时文件没有几个眼睛捕手(3d3d),不经常重复.它们表示新的二进制记录的开始.我需要根据那些眼睛捕手来分割文件.
我想要的输出是拥有多个文件(基于我的临时文件中的眼罩数量).
所以我的输出看起来像这样 –
$cat temp1 3d3d01f87347545002f1d5b2be4ee4d700010100018000cc57e582000000000000000 0000000000087d3f513000000000000000000000000000000000001001001010f00000000 002658783100b354c52658783100b4 $cat temp2 3d3d0000ad6413400103231665f301010b9130194899f2ffffffffffff02007c00dc0 15800a040402802f1d5b2b8ca5674504f4330310000000000046363070000000000000000 000000000065450000b4fb6b400039 $cat temp3 3d3d1116cdcc57e58287d3f55285a1084b
#!/usr/bin/perl undef $/; $_ = <>; $n = 0; for $match (split(/(?=3d3d)/)) { open(O,'>temp' . ++$n); print O $match; close(O); }