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...
Want to share photos of your group with the world? Add a group photo to Flickr.

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
Unable to deliver your message   Message List  
Reply | Forward Message #218 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









________________________________________________________________________________\
____
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]




Mon Mar 12, 2007 1:32 pm

kaushik_908
Offline Offline
Send Email Send Email

Forward
Message #218 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 BR
kaushik_908
Offline Send Email
Mar 20, 2007
12:40 pm
Advanced

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