summaryrefslogtreecommitdiff
path: root/test/redfilnm.awk
blob: 83cb6aa900d4b5f6bf91586d758073d07456cf0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#Date: Tue, 18 May 1999 12:48:07 -0500 (CDT)
#From: Darrel Hankerson <hankedr@dms.auburn.edu>
#To: arnold@gnu.org
#Subject: [christopher.procter@bt.com: RE: Getline bug in Gawk 3.0.3]
#
#Here's a reply that came directly to me.  --darrel
#
#
#From: christopher.procter@bt.com
#To: hankedr@dms.auburn.edu
#Subject: RE: Getline bug in Gawk 3.0.3
#Date: Tue, 18 May 1999 18:42:28 +0100
#
#Sorry that was me getting carried away and cut and pasting the wrong thing
#into my email
#
#The real problem seems to be that :
#BEGIN {
#for (i=1;i<10;i++){
#	while((getline < "hello.txt")>0){
# 		print $0
#		}
# 	close("hello.txt")
#	}
#}
#works (printing the contents of hello.txt 9 times), where as:-
#
#END{
#for (i=1;i<10;i++){
#	while((getline < "hello.txt")>0){
# 		print $0
#		}
# 	close("hello.txt")
#	}
#}
#
#doesn't, (it prints out hello.txt once followed by the iteration numbers
#from 1 to 9).
#The only difference is that one is in the BEGIN block and one in the END
#block.
#
#Sorry about the first post, I'm not a bad awk programmer, just a tired one
#:)
#
#chris
#
#> -----Original Message-----
#> From:	Darrel Hankerson [SMTP:hankedr@dms.auburn.edu]
#> Sent:	18 May 1999 18:28
#> To:	christopher.procter@bt.com
#> Subject:	Re: Getline bug in Gawk 3.0.3
#> 
#> Could you clarify?  Your first script uses an apparently undefined
#> variable f.
#> 
#> 
#> christopher.procter@bt.com writes:
#> 
#>    BEGIN {
#>    for (i=1;i<10;i++){
#>    while((getline < "hello.txt")>0){
#>      print $0
#>    }
#>      close(f)
#>    }
#>    }
#> 
#>    refuses to close the file and so prints the contents of hello.txt just
#> once.
#>    However:-
#> 
#>    BEGIN {
#>    f="hello.txt"
#>    for (i=1;i<10;i++){
#>    while((getline < f)>0){
#>      print $0
#>    }
#>      close(f)
#>    }
#>    }
#> 
#>    works as advertised (printing the contents of hello.txt 9 times)
#>    It seems like a bug in the close statement.
#> 
#> -- 
#> --Darrel Hankerson hankedr@mail.auburn.edu
#

# srcdir is assigned on command line --- ADR
END {
	f = srcdir "/redfilnm.in"
	for (i = 1; i < 10; i++){
		while((getline < f) > 0){
 			print $0
		}
 		close(f)
	}
}