Hi All,
I'm trying to read a file which looks as below ( There are thousands of these
records in the file )-
<BEGINREC>
ID -!- 359494
-!- ST -!- Outstanding
-!- MO -!- OSI_SYSTEM nuncp-tns_ns:.nuncp-temip_osilocal TESTOBJ "vtet"
-!- TE -!- { nuNCASNetwork nuncp-tns_ns:.nuncas }
-!- AT -!- CommunicationsAlarm
-!- ET -!- Tue, Mar 6, 2007 08:00:14 AM
-!- PC -!- TransmissionError
-!- PS -!- Critical
-!- ADT -!- "VTET: VTET Run failed."
<ENDREC>
<BEGINREC>
ID -!- 359493
-!- ST -!- Outstanding
-!- MO -!- OSI_SYSTEM nuncp-tns_ns:.nuncp-temip_osilocal TESTOBJ "vtet"
-!- TE -!- { nuNCASNetwork nuncp-tns_ns:.nuncas }
-!- AT -!- ProcessingErrorAlarm
-!- ET -!- Tue, Mar 6, 2007 08:00:03 AM
-!- PC -!-
PerformanceDegraded
-!- PS -!- Indeterminate
-!- ADT -!- "VTET Another instance is already Running;A VTET process is already
running."
<ENDREC>
<BEGINREC>
ID -!- 359492
-!- ST -!- Outstanding
-!- MO -!- OSI_SYSTEM nuncp-tns_ns:.nuncp-temip_osilocal TESTOBJ "vtet"
-!- TE -!- { nuNCASNetwork nuncp-tns_ns:.nuncas }
-!- AT -!- CommunicationsAlarm
-!- ET -!- Tue, Mar 6, 2007 03:00:14 AM
-!- PC -!- TransmissionError
-!- PS -!- Critical
-!- ADT -!- "VTET: VTET Run failed."
<ENDREC>
I'm
trying to populate each element of the array my_array with a single line in the
file b/w the <BEGINREC> & <ENDREC> record delimiters.
my_array[0]= ID -!- 359494
my_array[1]= -!- ST -!- Outstanding
.
.
.
The bit of code I'm using to do this operation is as under -
awk
-F"-!-" 'BEGIN{ TotalAlarms=0; InvalidAlarms=0; OutstandingAlarms=0;
TerminatedAlarms=0; AcknowledgedAlarms=0 }
/\<BEGINREC\>/,/\<ENDREC\>/ {}
/^<BEGINREC>/ { arr_Index = 0 }
{
if ( $0 !~ /^<ENDREC>/ && $0 !~ /^<BEGINREC>/ )
{
#printf "Line : %s\n", $0
#count = split ($0,Array,"-!-")
my_Array[$arr_Index]=sprintf("%s",$0)
printf ("-- Array %s : @ %d \n",my_Array[$arr_Index],arr_Index )
arr_Index++
}
if ( $0 ~ /<ENDREC>/ )
{
print "Hope to see something in the array\n"
for ( i=0; i <= arr_Index; i++ )
{
printf ("Array Here @ %d is %s \n",i,my_Array[$i] )
}
}
}' /tmp/Recordfile
I'm unable to print the values stored in the array in the print
statement
if ( $0 ~ /<ENDREC>/ )
{
print "Hope to see something in the array\n"
for ( i=0; i <= arr_Index; i++ )
{
printf ("Array Here @ %d is %s \n",i,my_Array[$i] )
}
}
Can someone please help.
Thanks and regards
Kaushik
________________________________________________________________________________\
____
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
[Non-text portions of this message have been removed]