split file based on group count

Hi,

can some one please help me to split the file based on groups.

like in the below scenario x indicates the begining of the group and the file should be split each with 2 groups below there are 10 groups it should create 5 files. could you please help?

awk '/^X/ {x+=1; if(x%2){z+=1}} {print >> "file_"z}' infile

Post expected output according to the input file which you posted.

Thanks for the replies!!!!

Zaxxon - getting the error message awk: 0602-575 Cannot find or open file file_.

expected output files would be 2 tables will be placed in each file and 5 different files would be created.

===========FILE1==================
X ABCDE1
Z SSSSSSSSS
Z EEEEEEEEEE
Z QQQQQQQQ
X XYAW2
Y akldsf;dsaf
Y akjdsf;asdfj
Y akjfd;asfsaf
============FILE2=================
X ABCDE3
Z SSSSSSSSS
Z EEEEEEEEEE
Z QQQQQQQQ
X XYAW4
Y akldsf;dsaf
Y akjdsf;asdfj
Y akjfd;asfsaf
============FILE3=================
X ABCDE5
Z SSSSSSSSS
Z EEEEEEEEEE
Z QQQQQQQQ
X XYAW6
Y akldsf;dsaf
Y akjdsf;asdfj
Y akjfd;asfsaf
============FILE4=================
X ABCDE7
Z SSSSSSSSS
Z EEEEEEEEEE
Z QQQQQQQQ
X XYAW8
Y akldsf;dsaf
Y akjdsf;asdfj
Y akjfd;asfsaf
============FILE5=================
X ABCDE9
Z SSSSSSSSS
Z EEEEEEEEEE
Z QQQQQQQQ
X XYAW10
Y akldsf;dsaf
Y akjdsf;asdfj
Y akjfd;asfsaf

one > should be fine. Maybe that's the reason to get the error "0602-575 Cannot find or open file"

awk '/^X/ {x+=1; if(x%2){z+=1}} {print > "file" z}' infile