AWK extraction

Hi all,
Can anyone please help me in parsing the following file. Suppose the file is called, example.lst, and has the following content in it.

(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(Host = 192.168.2.2)
(Port = 1525)
)
)
(CONNECT_DATA = (SID = TESTDB1)
)
)

(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(Host = 192.168.2.4)
(Port = 1525)
)
)
(CONNECT_DATA = (SID = TESTDB2)
)
)

I want to extract only the value of all Host (i.e, 192.168.2.4, 192.168.2.2) and value of all SID (i.e., TESTDB1, TESTDB2) from this file. Depending on the number of HOST and SID present in the file, i want to assign them to arrays, like

host[1]=192.168.2.2
host[2]=192.168.2.4
sid[1]=TESTDB1
sid[2]=TESTDB2 and so on....

I am trying this script in Korn shell. I am working with AWK.

Any help would be greatly appreciated.

Thanks,
Harris

check the following one

awk '{ split($0, arr, "=" ); if ( match($0, "Host") ) { host[i++]=substr(arr[2], 2, length(arr[2]) - 2) } else if ( match($0, "SID") ) { db[j++]=substr(arr[3], 2, length(arr[3]) - 2); } }' filename

to display the values in array and test

awk '{ split($0, arr, "=" ); if ( match($0, "Host") ) { host[i++]=substr(arr[2], 2, length(arr[2]) - 2) } else if ( match($0, "SID") ) { db[j++]=substr(arr[3], 2, length(arr[3]) - 2); } }END{ for ( x=0; x<i; x++ ) { print host[x] } for ( x=0; x<j; x++ ) { print db[x] } }' filename

nawk -f harris.awk example.lst

harris.awk:

BEGIN {
  RS=""
  FS="[() =]"
}
{
  for(i=1; i<=NF; i++) {
    if($i == "Host")
      host[FNR]=$(i+3)
    if($i == "SID")
      sid[FNR]=$(i+3)
  }
}
END {
  for(i in host)
    printf("host->[%s] sid->[%s]\n", host, sid)
}

Hi,
Hope this can help you.

awk 'BEGIN{
j=1
l=1
RS=""
FS="\n"
}
{
for (i=1;i<=NF;i++)
{
  if($i ~ /Host/)
  {
	host[j]=substr($i,8,length($i)-8)
  	j=j+1
  }
  if ($i ~ /SID/)
  {
  	sid[l]=substr($i,23,length($i)-23)
        l=l+1
  }
}
}
END{
for (k in host)
{
print host[k]
print sid[k]
}
}' a