AWK script problem insertion of code

Hi ,

I am having two files like this

 
FILE1 
####################
 
input SI_TESTONLY_R_00;
input CE0_SE_INPUT_TESTONLY;
input CE0_TCLK_TESTONLY;
input SI_JTGCLOCKDR_JTAG_R_00;
input CE0_TCLK_JTGCLOCKDR_JTAG;
input CE0_SE_INPUT_JTGCLOCKDR_JTAG;
output SO_TESTONLY_R_00;
output SO_JTGCLOCKDR_JTAG_R_00;
 

#######################

FILE2

 
#########################
 
SDFFQ_X1M_A9TH P1_sdflop (
.CK (P2)
.D (1'b0),
.SI (P1),
.SE (P3),
.Q (P1_INT_NET));
 
LATNQ_X1M_A9TH P1_lockup (
 .GN (P2),
.D (P1_INT_NET),
.Q (P5));

#########################

Now FILE1 is very big file having lots of pins like this
Need to match the pattern SI_TESTONLY with other same kind of patterns pins CE0_SE_INPUT_TESTONLY and CE0_TCLK_TESTONLY

and insert the code from the second file into the First File with the replacement
P1 : SI_* Pin
P2 :CE0_TCLK* Pin
P3: CE0_SE_INPUT* Pin
P5: SO_TESTONLY_R_00 Pin

OUTPUT FILE
:mad:

 
########################
 
input SI_TESTONLY_R_00;
input CE0_SE_INPUT_TESTONLY;
input CE0_TCLK_TESTONLY;
input SI_JTGCLOCKDR_JTAG_R_00;
input CE0_TCLK_JTGCLOCKDR_JTAG;
input CE0_SE_INPUT_JTGCLOCKDR_JTAG;
output SO_TESTONLY_R_00;
output SO_JTGCLOCKDR_JTAG_R_00;
 
SDFFQ_X1M_A9TH SI_TESTONLY_R_00_sdflop (
.CK (CE0_TCLK_TESTONLY)
.D (1'b0),
.SI (SI_TESTONLY_R_00),
.SE (CE0_SE_INPUT_TESTONLY),
.Q (SI_TESTONLY_R_00_INT_NET));
 
LATNQ_X1M_A9TH P1_lockup (
 .GN (CE0_TCLK_TESTONLY),
.D (SI_TESTONLY_R_00_INT_NET),
.Q (SO_TESTONLY_R_00));


SDFFQ_X1M_A9TH SI_JTGCLOCKDR_JTAG_R_00_sdflop (
.CK (CE0_TCLK_JTGCLOCKDR_JTAG)
.D (1'b0),
.SI (SI_JTGCLOCKDR_JTAG_R_00),
.SE (CE0_SE_INPUT_JTGCLOCKDR_JTAG),
.Q (SI_JTGCLOCKDR_JTAG_R_00_INT_NET));
 
LATNQ_X1M_A9TH P1_lockup (
 .GN (CE0_TCLK_JTGCLOCKDR_JTAG),
.D (SI_JTGCLOCKDR_JTAG_R_00_INT_NET),
.Q (SO_JTGCLOCKDR_JTAG_R_00));


 

I tried to used the array variables but could not build the relevant script on this issue

Please help me out on this

Thanks

Jaita

---------- Post updated at 10:26 AM ---------- Previous update was at 03:22 AM ----------

Anyone Can please help me out in this particular issue

Thanks
Jaita

What have you tried so far (show the code please), where are you stuck, how does your output not match the expected output, ...
We're not here to do your work for you.

I tried the below Flow

I did some vi editing work to create the File as shown below

 
FILE1 
###########################
 
input SI_TESTONLY_R_00;
input CE0_SE_INPUT_TESTONLY;
input CE0_TCLK_TESTONLY;
output SO_TESTONLY_R_00;

input SI_JTGCLOCKDR_JTAG_R_00;
input CE0_TCLK_JTGCLOCKDR_JTAG;
input CE0_SE_INPUT_JTGCLOCKDR_JTAG;
output SO_JTGCLOCKDR_JTAG_R_00;

but these pins are in different order

Appended the FIle like this

 
cat FILE2 >> FILE1 
 
awk '{a[FNR]=$2 } END { gsub(P1,a[0]), gsub(P2,a[1], gsub(P3,a[2]) ,gsub(P5,a[3}1' FILE1 
 
cat FILE2 >> FILE1 
 
 
awk '{a[FNR]=$2 } END { gsub(P1,a[0]), gsub(P2,a[1], gsub(P3,a[2]) ,gsub(P5,a[3}1' FILE1 

In this way I am trying to get the output

But it is very messy

Can you help me to make this code more versatile

Issues

a)Sorting of the Pins according to the Pattern match

b) Looping the stuff to insert the Code like the Output File

I did the Initial work before writing the mail and thats why I asked for help , If you think you can help me out I am indebted to you

Thanks
Jaita