ashikin_8119 0 Newbie Poster

Hi all;

I have a file that i need to sort and batch with certain criterias. For every 5 lines that meet the criteria i need to add '1' above it to separate it with other batch.

The original file look like this:

20080201A300000357701 80058+117.06 02
20080201A300000357701 80058-117.06 02
20080201A300000382309 80058+279.93 02
20080202A300000382504 80058+196.15 02
20080201A300000382504 80058-196.15 02
20080201A350000443109 80058+341.65 02
20080201A350000443109 80058-341.65 02
20080201A400002250606 80058+3609.19 02
20080201A400002250606 80058-3609.19 01
20080201A400002250704 80058+1395.17 02

I need to transform the file to be like this :

0
1
20080201A400002250606 80058-3609.19 01
1
20080201A300000357701 80058+117.06 02
20080201A300000357701 80058-117.06 02
20080201A300000382309 80058+279.93 02
20080201A300000382504 80058-196.15 02
20080201A350000443109 80058+341.65 02
1
20080201A350000443109 80058-341.65 02
20080201A400002250606 80058+3609.19 02
20080201A400002250704 80058+1395.17 02
1
20080202A300000382504 80058+196.15 02

Basically i need to batch the file if the first 8 character and character 55-57 is different. I already have the solution for that. Only when the batch exceed 5 rows, i need to break up the batch into batches.

Someone pls help me to modify my awk script to add one more criteria in which it needs to split to another batch (add '1') if the count is 5.

This is the script that i use:

sort -k1.1,1.8n -k1.55,1.56n testfile.1 | awk '
FNR==1{print 0} !x[ substr($0,1,8),substr($0,55,2)] ++ {print 1}1
'

Thank you in advance ...