File transpose problem

Hi Friends,

I have a file with a structure like this:

<file1.csv>
field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12

Few Salient points on the file's structure
(1)The fields from field1 to field6 is fixed and they would always be present in the file
(2)The field7-field8 is a block and that block of two fields gets repeated variably from three as in the present example ([field7,field8],[field9,field10],[field11,field12]) to any number. There can 10 such instances of these blocks of two fields as well as 20 or even lower down to only 1(wherein you have only field7,field8)

My objective is to create two such files from this file
(1) file1 will have seven fields, the fixed six fields from field1 to field6 and a seventh field with values containing filename and a sequencenumber(unique for each record)
(2) file2 will have the three fields. the first field will contain the filename and the sequencenumber. This is such to tie the records of file2 to file1.
And the other two fields will be for the block of two fields.
So if in the original file we have 3 instances of these blocks, we would have three records in the file for them.

Please help me in this.

regards

Hi,

it would be nice if you could show the sample data for input and output files.

Here is some sample data of the files:

The source file is having data like:
<file1.csv>
field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12

sample data:
1,ABC001,Tropical Rainforest,Americas,Sacramento,Mr David Cemes,123,Subway,456,McDonalds,977,KFC

Depending on my requirement,

New file1 should have:
field1,field2,field3,field4,field5,field6,field7,field8

sample data being:
1,ABC001,Tropical Rainforest,Americas,Sacramento,Mr David Cemes,file1_0001

and file2 should have:
field1,field2,field3

sample data being:
file1_0001,123,Subway
file1_0002,456,McDonalds
file1_003,977,KFC