Copy data and send it to other file, with diff config

I need a new script to 'grep' data from files in var
and send it to another file in var folder with diff output,
but like you now my Now How is very, very small then to have a idea is something like this:

in file text1.txt have a few lines like this one:

Y: { XXX1 { XXX2 YYYY { IIIIIIII { AA BB }}}}

Variavel:
XXX1
XXX2
YYYY
IIIIIIII
AA
BB

and I whant to send it to file text2.txt
with this output:

G: 88888888 LLLLLLL 55555 IIIIIIII XXX1 YYYY

where 88888888 LLLLLLL 55555, is in all the lines the same and i need to add Y lines but
only the variavel's IIIIIIII XXX1 YYYY in G lines.

File text1.txt is in folder /var/ and text2.txt is in folder /var/ to.

I need also to read conf file with data and send it to diferent files, like:

my.conf

Data:
==============
SERVER_PORT=20000 send it to ports.cfg in var like this:
SERVER PORT : 20000
USER=root send it to ports.cfg in var like this:
USERNAME : root
PASS=pass send it to ports.cfg in var like this:
PASS : pass
Port=16000 send it to portsall.cfg in var like this:
Port          = 16000
==============
Device= XXXXXX 
PortDevice1=16000 send it to portsall.cfg in var like this: 
Device           = XXXXX,16000
==============
UDP_HOST=192.168.1.110
TCP_HOST=192.168.1.110
UDP_PORT=1000
TCP_PORT=3001  send it to config.xml in var like this:

<udp_host>192.168.1.110</udp_host>
<tcp_host>192.168.1.110</tcp_host>
<udp_port>1000</udp_port>
<tcp_port>3001</tcp_port>

In text1.txt I have Z line too and i need to add to conf to

zebrareport=0110
zebraip=10.0.0.2
zebraudpport=8024 and send it to text1.txt in var like this:

Z: { 01 10 } 10.0.0.2 8024

Well if you help me with this i will very happy, Thank's. :smiley:

Note: Froget in files there is coments "#", this is not to display or show, then ignore coments.
Sorry for my english... :smiley:
I think i explained well but any question i will try to explained better...