Search the web
Sign In
New User? Sign Up
geeksthatgawk · for GNU Awk questions & discussions
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Arry values not visible   Message List  
Reply | Forward Message #219 of 221 |
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




Mon Mar 12, 2007 1:35 pm

kaushik_908
Offline Offline
Send Email Send Email

Forward
Message #219 of 221 |
Expand Messages Author Sort by Date

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 ...
kaushik_908
Offline Send Email
Mar 20, 2007
12:41 pm

Hi Kaushik, Try removing the "$" in ALL the array references, for example: my_Array[$arr_Index] becomes my_Array[arr_Index] Ambo The bit of code...
Ambrosio Berdijo
aberdijo
Offline Send Email
Mar 22, 2007
3:47 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help