For Programmers: Free Programming Magazines  


Home > Archive > AWK > October 2006 > tawk: endfile & getline









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author tawk: endfile & getline
Peter V. Saveliev

2006-10-17, 7:55 am

....

Can anybody using tawk run next code:

$ awk -f test.awk test.2 test.1

....

#8<- test.awk ------------------------------------------------------
{
print FILENAME": before: "$0
getline
print FILENAME": after: "$0
}

ENDFILE {
print "endfile for "FILENAME
}
#8<-----------------------------------------------------------------

data file test.2 (only 3 lines):

1
2
3

data file test.1 (only 2 lines):

1
2

....

and show the output? Thanks a lot.

Kenny McCormack

2006-10-17, 7:55 am

In article <1161082719.755732.317700@i3g2000cwc.googlegroups.com>,
Peter V. Saveliev <peet@peet.spb.ru> wrote:
>...
>
>Can anybody using tawk run next code:
>
>$ awk -f test.awk test.2 test.1
>
>...
>
>#8<- test.awk ------------------------------------------------------
>{
> print FILENAME": before: "$0
> getline
> print FILENAME": after: "$0
>}
>
>ENDFILE {
> print "endfile for "FILENAME
>}


I got what I expected, but it is interesting. I never thought about
triggering an ENDFILE rule from within another rule (only possible via
getline). But it does work as expected:

C:\>awkw -f pete file1 file2
file1: before: 1
file1: after: 2
file1: before: 3
endfile for file1
file2: after: 1
file2: before: 2
endfile for file2
file2: after:

C:\>

I assume that BEGINFILE would behave similarly.

Juergen Kahrs

2006-10-17, 7:55 am

Kenny McCormack wrote:

>
> I got what I expected, but it is interesting. I never thought about
> triggering an ENDFILE rule from within another rule (only possible via
> getline). But it does work as expected:


Peter and Manuel are currently exploring such corner cases
in their discussion on the xmlgawk mailing list. Manuel has
already found some interesting cases and Peter has already
fixed some bugs in his implementation.

>
> C:\>awkw -f pete file1 file2
> file1: before: 1
> file1: after: 2
> file1: before: 3
> endfile for file1
> file2: after: 1
> file2: before: 2
> endfile for file2
> file2: after:


I think that's what Peter wanted to know.

>
> C:\>
>
> I assume that BEGINFILE would behave similarly.
>


If you are interested in such details (user expectations,
symmetry of BEGINFILE and ENDFILE) you are invited to
contribute your comments to the mailing list:

http://lists.sourceforge.net/lists/...o/xmlgawk-users
http://lists.sourceforge.net/lists/...lgawk-developer

Thanks for trying Peter's test case cited above.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com