Splitting a file incrementally

Dear all,

I would like to split a file incrementally. My file looks like:

$path {
$name "path_sparc_ifu_dec_1" ;
$transition {
"dtu_inst_d[22]"	v	;	//	(in)
"U622/Y"	^	;	//	(INVX16_LVT)
"U870/Y"	^	;	//	(AND2X1_LVT)
"U873/Y"	v	;	//	(INVX1_LVT)
"U872/Y"	^	;	//	(NAND3X0_LVT)
"U1045/Y"	v	;	//	(NAND3X0_LVT)
"U1046/Y"	^	;	//	(NAND3X0_LVT)
"U1063/Y"	^	;	//	(OR3X1_LVT)
"U1092/Y"	^	;	//	(OR3X1_LVT)
"U1095/Y"	^	;	//	(OA21X1_LVT)
"illinste_ff_q_reg_0_/D"	^	;	//	(DFFX1_LVT)
}
}
$path {
$name "path_sparc_ifu_dec_2" ;
$transition {
"dtu_inst_d[22]"	^	;	//	(in)
"U622/Y"	v	;	//	(INVX16_LVT)
"U870/Y"	v	;	//	(AND2X1_LVT)
"U873/Y"	^	;	//	(INVX1_LVT)
"U872/Y"	v	;	//	(NAND3X0_LVT)
"U1045/Y"	^	;	//	(NAND3X0_LVT)
"U1046/Y"	v	;	//	(NAND3X0_LVT)
"U1063/Y"	v	;	//	(OR3X1_LVT)
"U1092/Y"	v	;	//	(OR3X1_LVT)
"U1095/Y"	v	;	//	(OA21X1_LVT)
"illinste_ff_q_reg_0_/D"	v	;	//	(DFFX1_LVT)
}
}
$path {
$name "path_sparc_ifu_dec_3" ;
$transition {
"dtu_inst_d[22]"	v	;	//	(in)
"U622/Y"	^	;	//	(INVX16_LVT)
"U782/Y"	^	;	//	(AND2X1_LVT)
"U781/Y"	^	;	//	(AND2X1_LVT)
"U632/Y"	v	;	//	(INVX0_LVT)
"U999/Y"	^	;	//	(NAND4X0_LVT)
"U1000/Y"	v	;	//	(NAND2X0_LVT)
"U1006/Y"	^	;	//	(NAND4X0_LVT)
"U1007/Y"	^	;	//	(AND4X1_LVT)
"prope_ff_q_reg_0_/D"	^	;	//	(DFFX1_LVT)
}
}
.
.
.

I would like to have files which have "path" incrementally.
The 1st file has the 1st path. The 2nd file has the 1st and 2nd paths. The 3rd file has the 1st, 2nd, and 3rd paths. This incremental splitting will be continued the end of the original file. (upto n).

P1:

$path {
$name "path_sparc_ifu_dec_1" ;
$transition {
"dtu_inst_d[22]"	v	;	//	(in)
"U622/Y"	^	;	//	(INVX16_LVT)
"U870/Y"	^	;	//	(AND2X1_LVT)
"U873/Y"	v	;	//	(INVX1_LVT)
"U872/Y"	^	;	//	(NAND3X0_LVT)
"U1045/Y"	v	;	//	(NAND3X0_LVT)
"U1046/Y"	^	;	//	(NAND3X0_LVT)
"U1063/Y"	^	;	//	(OR3X1_LVT)
"U1092/Y"	^	;	//	(OR3X1_LVT)
"U1095/Y"	^	;	//	(OA21X1_LVT)
"illinste_ff_q_reg_0_/D"	^	;	//	(DFFX1_LVT)
}
}

P2:

$path {
$name "path_sparc_ifu_dec_1" ;
$transition {
"dtu_inst_d[22]"	v	;	//	(in)
"U622/Y"	^	;	//	(INVX16_LVT)
"U870/Y"	^	;	//	(AND2X1_LVT)
"U873/Y"	v	;	//	(INVX1_LVT)
"U872/Y"	^	;	//	(NAND3X0_LVT)
"U1045/Y"	v	;	//	(NAND3X0_LVT)
"U1046/Y"	^	;	//	(NAND3X0_LVT)
"U1063/Y"	^	;	//	(OR3X1_LVT)
"U1092/Y"	^	;	//	(OR3X1_LVT)
"U1095/Y"	^	;	//	(OA21X1_LVT)
"illinste_ff_q_reg_0_/D"	^	;	//	(DFFX1_LVT)
}
}
$path {
$name "path_sparc_ifu_dec_2" ;
$transition {
"dtu_inst_d[22]"	^	;	//	(in)
"U622/Y"	v	;	//	(INVX16_LVT)
"U870/Y"	v	;	//	(AND2X1_LVT)
"U873/Y"	^	;	//	(INVX1_LVT)
"U872/Y"	v	;	//	(NAND3X0_LVT)
"U1045/Y"	^	;	//	(NAND3X0_LVT)
"U1046/Y"	v	;	//	(NAND3X0_LVT)
"U1063/Y"	v	;	//	(OR3X1_LVT)
"U1092/Y"	v	;	//	(OR3X1_LVT)
"U1095/Y"	v	;	//	(OA21X1_LVT)
"illinste_ff_q_reg_0_/D"	v	;	//	(DFFX1_LVT)
}
}

P3:

$path {
$name "path_sparc_ifu_dec_1" ;
$transition {
"dtu_inst_d[22]"	v	;	//	(in)
"U622/Y"	^	;	//	(INVX16_LVT)
"U870/Y"	^	;	//	(AND2X1_LVT)
"U873/Y"	v	;	//	(INVX1_LVT)
"U872/Y"	^	;	//	(NAND3X0_LVT)
"U1045/Y"	v	;	//	(NAND3X0_LVT)
"U1046/Y"	^	;	//	(NAND3X0_LVT)
"U1063/Y"	^	;	//	(OR3X1_LVT)
"U1092/Y"	^	;	//	(OR3X1_LVT)
"U1095/Y"	^	;	//	(OA21X1_LVT)
"illinste_ff_q_reg_0_/D"	^	;	//	(DFFX1_LVT)
}
}
$path {
$name "path_sparc_ifu_dec_2" ;
$transition {
"dtu_inst_d[22]"	^	;	//	(in)
"U622/Y"	v	;	//	(INVX16_LVT)
"U870/Y"	v	;	//	(AND2X1_LVT)
"U873/Y"	^	;	//	(INVX1_LVT)
"U872/Y"	v	;	//	(NAND3X0_LVT)
"U1045/Y"	^	;	//	(NAND3X0_LVT)
"U1046/Y"	v	;	//	(NAND3X0_LVT)
"U1063/Y"	v	;	//	(OR3X1_LVT)
"U1092/Y"	v	;	//	(OR3X1_LVT)
"U1095/Y"	v	;	//	(OA21X1_LVT)
"illinste_ff_q_reg_0_/D"	v	;	//	(DFFX1_LVT)
}
}
$path {
$name "path_sparc_ifu_dec_3" ;
$transition {
"dtu_inst_d[22]"	v	;	//	(in)
"U622/Y"	^	;	//	(INVX16_LVT)
"U782/Y"	^	;	//	(AND2X1_LVT)
"U781/Y"	^	;	//	(AND2X1_LVT)
"U632/Y"	v	;	//	(INVX0_LVT)
"U999/Y"	^	;	//	(NAND4X0_LVT)
"U1000/Y"	v	;	//	(NAND2X0_LVT)
"U1006/Y"	^	;	//	(NAND4X0_LVT)
"U1007/Y"	^	;	//	(AND4X1_LVT)
"prope_ff_q_reg_0_/D"	^	;	//	(DFFX1_LVT)
}
}

Could you let me know how to do this job? Any language (sed,awk,grep) are okay to me.

Best,

Jaeyoung

Hello jypark22,

Could you please try following and let me know if this helps you.

awk '/^\$path/{A++;if(A>0){print Q >> "P"A}} {if(A>=0){Q=Q?Q ORS $0:$0;}} END{A++;print Q > "P"A}' A=-1  Input_file

Thanks,
R. Singh

Is this a homework assignment?

If it is not a homework assignment, please explain why it is useful to create three files containing (collectively) six copies of a sixteen lines of text from one file containing three identical copies of sixteen lines of text.

Hi R. Singh,

Your code works perfectly. Thank you so much. I would appreciate your help.

  • Don

It would be the inputs of the automatic test pattern generator. I will use files by Singh's code as an input of ATPG.

Thank you.