Line Parsing using sed and awk

Hi Guys,

I need help with processing data in a file, line by line.

My file test.txt has

X_Building_X5946/X0 BUT/U_msp/RdBuMon_d2_B_00 BUT/U_msp/FfRmDaMix_d2_Pi3[28] Test_Long xp=849.416 yp=245.82 xn=849.488 yn=245.82 w=0.476 l=0.072 fault_layer="Al_T01_Mod" $[M1_BRI_TYPE1_P1] $X=849416 $Y=245582
X_Building_X5946/X1 BUT/U_msp/RdBuMon_d2_B_00 BUT/U_msp/FfRmDaMix_d2_Pi3[29] Test_Long xp=849.416 yp=247.86 xn=849.488 yn=247.86 w=0.476 l=0.072 fault_layer="Al_T01_Mod" $[M1_BRI_TYPE1_P1] $X=849416 $Y=247622
X_Building_X5946/X2 BUT/U_msp/RdBuMon_d2_B_00 BUT/U_msp/FfRmDaMix_d2_Pi3[30] Test_Long xp=849.416 yp=249.9 xn=849.488 yn=249.9 w=0.476 l=0.072 fault_layer="Al_T01_Mod" $[M1_BRI_TYPE1_P1] $X=849416 $Y=249662
X_Building_X5946/X3 BUT/U_msp/RdBuMon_d2_B_00 BUT/U_msp/FfRmDaMix_d2_Pi3[31] Test_Long xp=849.416 yp=251.94 xn=849.488 yn=251.94 w=0.476 l=0.072 fault_layer="Al_T03_Mod" $[M1_BRI_TYPE2_P1] $X=849416 $Y=251702
X_Building_X5946/X4 BUT/U_msp/RdFfData2Sr_d2_BUF_00 BUT/U_msp/FfRmDaMix_d2_Pi2[28] Test_Long xp=850.952 yp=245.82 xn=851.024 yn=245.82 w=0.476 l=0.072 fault_layer="Al_T02_Mod" $[M1_BRI_TYPE3_P1] $X=850952 $Y=245582

I need to process each line. i.e if you observe each line starts with X_Building_ and ends with $Y=number

I need my output to be

EGDIR "X_Building_X5946/X0.M1_BRI_TYPE1_P1" {
  NET1="/iDUT/BUT/U_msp/RdBuMon_d2_B_00";
  NET2="/iDUT/BUT/U_msp/FfRmDaMix_d2_Pi3 [28]";
  LENGTH=0.072;
  WIDTH=0.476;
  X_COORDINATE=849416;
  Y_COORDINATE=245582;
  LAYER="Al_T01_Mod";
}
EGDIR "X_Building_X5946/X1.M1_BRI_TYPE1_P1" {
  NET1="/iDUT/BUT/U_msp/RdBuMon_d2_B_00";
  NET2="/iDUT/BUT/U_msp/FfRmDaMix_d2_Pi3 [29]";
  LENGTH=0.072;
  WIDTH=0.476;
  X_COORDINATE=849416;
  Y_COORDINATE=247622;
  LAYER="Al_T01_Mod";
}
EGDIR "X_Building_X5946/X2.M1_BRI_TYPE1_P1" {
  NET1="/iDUT/BUT/U_msp/RdBuMon_d2_B_00";
  NET2="/iDUT/BUT/U_msp/FfRmDaMix_d2_Pi3 [30]";
  LENGTH=0.072;
  WIDTH=0.476;
  X_COORDINATE=849416;
  Y_COORDINATE=249662;
  LAYER="Al_T01_Mod";
}
EGDIR "X_Building_X5946/X3.M1_BRI_TYPE2_P1" {
  NET1="/iDUT/BUT/U_msp/RdBuMon_d2_B_00";
  NET2="/iDUT/BUT/U_msp/FfRmDaMix_d2_Pi3 [31]";
  LENGTH=0.072;
  WIDTH=0.476;
  X_COORDINATE=849416;
  Y_COORDINATE=251702;
  LAYER="Al_T03_Mod";
}
EGDIR "X_Building_X5946/X4.M1_BRI_TYPE3_P1" {
  NET1="/iDUT/BUT/U_msp/RdFfData2Sr_d2_BUF_00";
  NET2="/iDUT/BUT/U_msp/FfRmDaMix_d2_Pi2 [28]";
  LENGTH=0.072;
  WIDTH=0.476;
  X_COORDINATE=850952;
  Y_COORDINATE=245582;
  LAYER="Al_T02_Mod";
}

Thanking you all in Advance

awk '   /^X_Building_/ && /Y=[0-9]* *$/ {
print "EGDIR " qt $1".M1_BRI_TYPE1_P1" qt " {"
print "  NET1=" qt "/iDUT/"$2 qt ";"
print "  NET2=" qt "/iDUT/"$3 qt ";"
sub("l=","",$10);print "  LENGTH="$10 ";"
sub("w=","",$9);print "  WIDTH="$9 ";"
sub("\\$X=","",$(NF-1));print "  X_COORDINATE="$(NF-1) ";"
sub("\\$Y=","",$NF);print "  Y_COORDINATE="$NF  ";"
sub("fault_layer=","",$11);print "  LAYER=" $11 ";" } ' qt=\" file

Hi Anbu23,
Thanks a lot for the help.... I however noticed that in the line

print "EGDIR " qt $1".M1_BRI_TYPE1_P1" qt " {"

the value M1_BRI_TYPE1_P1 is a variable and changes every now and then. For eg in line 4 and 5 of Initial File. So I guess we need to strip off the $[ ] from column 12? How can that be done??

Thanks again,
Naveen