BSD 4_3 development
[unix-history] / usr / src / bin / awk / test.a
CommitLineData
483839cf
C
1!<arch>
2t.0 307335954 9 3 100664 23 `
3{i = i+1; print i, NR}
4
5t.1.x 307335954 9 3 100664 32 `
6{i="count" $1 $2; print i , $0}
7t.2.x 307335954 9 3 100664 31 `
8{i=2; j=$3; $1=i;print i,j,$1}
9
10t.3 307335954 9 3 100664 23 `
11$1 == "5" || $1 == "4"
12
13t.3.x 307335954 9 3 100664 50 `
14{
15x = $1
16while (x > 1) {
17 print x
18 x = x / 10
19}
20}
21t.4 307335954 9 3 100664 21 `
22$1 ~ /5/ || $1 ~ /4/
23
24t.4.x 307335954 9 3 100664 18 `
25{i=$(1); print i}
26t.5.x 307335954 9 3 100664 28 `
27{$(1) = "xxx"; print $1,$0}
28t.6 307335954 9 3 100664 76 `
29/a|b|c/ {
30 i = $1
31 print
32 while (i >= 1) {
33 print " ", i
34 i = i / 10
35 }
36}
37t.6.x 307335955 9 3 100664 14 `
38{print NF,$0}
39t.6a 307335955 9 3 100664 64 `
40/a|b|c/ {
41 print
42 for (i = $1; i >= 1; )
43 print " ", i /= 10
44}
45t.6b 307335955 9 3 100664 65 `
46/a|b|c/ {
47 print
48 for (i = $1; (i /= 10)>= 1; )
49 print " ", i
50}
51
52t.8.x 307335955 9 3 100664 15 `
53{$2=$1; print}
54
55t.a 307335955 9 3 100666 130 `
56 {if (amount[$2] "" == "") item[num++] = $2;
57 amount[$2] += $1
58 }
59END {for (i=0; i<num; i++)
60 print item[i], amount[item[i]]
61 }
62t.aeiou 307335955 9 3 100664 58 `
63/^[^aeiouy]*[aeiou][^aeiouy][aeiouy][aeiouy]*[^aeiouy]*$/
64t.aeiouy 307335955 9 3 100664 81 `
65/^[^aeiouy]*a[^aeiouy]*e[^aeiouy]*i[^aeiouy]*o[^aeiouy]*u[^aeiouy]*y[^aeiouy]*$/
66
67t.arith 307335955 9 3 100664 52 `
68{ print $1, $1+$1, $1-$1, $1 * $1, $1/$1, $1 % NR }
69t.array 307335955 9 3 100664 147 `
70 { x[NR] = $0 }
71
72END {
73 i = 1
74 while (i <= NR) {
75 print x[i]
76 split (x[i], y)
77 usage = y[1]
78 name = y[2]
79 print " ", name, usage
80 i++
81 }
82}
83
84t.array1 307335955 9 3 100664 123 `
85{for(i=1; i<=NF; i++) {
86 if (x[$i] == "")
87 y[n++] = $i
88 x[$i]++
89 }
90}
91END {
92 for (i=0; i<n; i++)
93 print (y[i], x[y[i]])
94}
95
96t.array2 307335955 9 3 100664 168 `
97$2 ~ /^[a-l]/ { x["a"] = x["a"] + 1 }
98$2 ~ /^[m-z]/ { x["m"] = x["m"] + 1 }
99$2 !~ /^[a-z]/ { x["other"] = x["other"] + 1 }
100END { print NR, x["a"], x["m"], x["other"] }
101t.avg 307335955 9 3 100664 80 `
102{s = s + $1; c = c + 1}
103END {
104print "sum=", s, " count=", c
105print "avg=", s/c
106}
107t.b.x 307335956 9 3 100664 36 `
108{$6=":::" ; print $6; print NF, $0}
109t.be 307335956 9 3 100664 42 `
110BEGIN { print FILENAME }
111END { print NR }
112t.break 307335956 9 3 100664 91 `
113{
114for (i=1; i <= NF; i++)
115 if ($i ~ /^[a-z]+$/) {
116 print $i " is alphabetic"
117 break
118 }
119}
120
121t.break1 307335956 9 3 100664 135 `
122 { x[NR] = $0 }
123END {
124 for (i = 1; i <= NR; i++) {
125 print i, x[i]
126 if (x[i] ~ /shen/)
127 break
128 }
129 print "got here"
130 print i, x[i]
131}
132
133t.break2 307335956 9 3 100664 122 `
134 { x[NR] = $0 }
135END {
136 for (i in x) {
137 print i, x[i]
138 if (x[i] ~ /shen/)
139 break
140 }
141 print "got here"
142 print i, x[i]
143}
144t.break3 307335956 9 3 100666 116 `
145{ for (i = 1; i <= NF; i++) {
146 for (j = 1; j <= NF; j++)
147 break;
148 print "inner", i, j
149 }
150 print "outer", i, j
151}
152t.bug1 307335985 9 3 100666 103 `
153# this program fails if awk is created without separate I&D
154# prints garbage if no $3
155{ print $1, $3 }
156
157t.cat 307335956 9 3 100664 114 `
158{print $2 " " $1}
159{print $1 " " "is", $2}
160{print $2 FS "is" FS $1}
161{print length($1 $2), length($1) + length($2)}
162t.cat1 307335957 9 3 100664 38 `
163{print x $0} # should precede by zero
164t.cat2 307335957 9 3 100664 21 `
165{$1 = $1 "*"; print}
166
167t.cmp 307335957 9 3 100664 8 `
168$2 > $1
169t.coerce 307335957 9 3 100664 47 `
170END { print i, NR
171 if (i < NR)
172 print i, NR
173}
174
175t.comment 307335957 9 3 100664 112 `
176# this is a comment line
177# so is this
178/#/ { print "this one has a # in it: " $0 # comment
179 print "again:" $0
180 }
181t.comment1 307335957 9 3 100664 88 `
182#comment
183 #
184BEGIN { x = 1 }
185/abc/ { print $0 }
186#comment
187END { print NR }
188#comment
189t.contin 307335957 9 3 100664 130 `
190{
191for (i = 1; i <= NF; i++) {
192 if ($i ~ /^[0-9]+$/)
193 continue;
194 print $i, " is non-numeric"
195 next
196}
197print $0, "is all numeric"
198}
199t.count 307335957 9 3 100664 17 `
200END { print NR }
201
202t.cum 307335957 9 3 100664 38 `
203{i = i + $1; print i}
204END {
205print i
206}
207t.d.x 307335958 9 3 100664 43 `
208BEGIN {FS=":" ; OFS=":"}
209{print NF " ",$0}
210
211t.e 307335958 9 3 100664 23 `
212$1 < 10 || $2 ~ /bwk/
213
214t.else 307335958 9 3 100664 46 `
215{ if($1>1000) print "yes"
216 else print "no"
217}
218t.exit 307335958 9 3 100664 32 `
219{ print }
220$1 < 5000 { exit NR }
221t.f 307335958 9 3 100664 15 `
222{print $2, $1}
223
224t.f.x 307335958 9 3 100664 26 `
225$1>0 {print $1, sqrt($1)}
226t.f0 307335959 9 3 100664 20 `
227$1 ~ /x/ {print $0}
228t.f1 307335959 9 3 100664 16 `
229{$1 = 1; print}
230t.f2 307335959 9 3 100664 19 `
231{$1 = 1; print $0}
232
233t.f3 307335959 9 3 100664 17 `
234{$1 = NR; print}
235
236t.f4 307335959 9 3 100664 20 `
237{$1 = NR; print $0}
238t.for 307335959 9 3 100664 39 `
239{ for (i=1; i<=NF; i++)
240 print i, $i
241}
242
243t.for1 307335959 9 3 100664 68 `
244{
245 i = 1
246 for (;;) {
247 if (i > NF)
248 next
249 print i, $i
250 i++
251 }
252}
253t.for2 307335960 9 3 100664 61 `
254{
255 for (i=1;;i++) {
256 if (i > NF)
257 next
258 print i, $i
259 }
260}
261
262t.format4 307335985 9 3 100664 127 `
263BEGIN {
264text=sprintf ("%125s", "x")
265print length (text)
266print text
267xxx=substr (text,1,105)
268print length (xxx)
269print xxx
270exit
271}
272
273t.func 307335960 9 3 100664 73 `
274{ print $1, length($1), log($1), sqrt($1), int(sqrt($1)), exp($1 % 10) }
275
276t.getline 307335984 9 3 100666 117 `
277{ x = $1
278 for (i = 1; i <= 3; i++)
279 if (getline)
280 x = x " " $1
281 print x
282 x = ""
283}
284END {
285 if (x != "") print x
286}
287
288t.i.x 307335960 9 3 100664 52 `
289{i=i+log($1); print i,log($1)}
290END {print exp(i),i}
291t.if 307335960 9 3 100664 21 `
292{if($1 || $2) print}
293
294t.in 307335960 9 3 100664 98 `
295BEGIN {
296 x["apple"] = 1;
297 x["orange"] = 2;
298 x["lemon"] = 3;
299 for (i in x)
300 print i, x[i]
301 exit
302}
303t.in1 307335960 9 3 100664 126 `
304 { if (amount[$2] == "")
305 name[++n] = $2
306 amount[$2] += $1
307 }
308END { for (i in name)
309 print i, name[i], amount[name[i]]
310 }
311t.in2 307335960 9 3 100664 68 `
312 { x[substr($2, 1, 1)] += $1 }
313END { for (i in x)
314 print i, x[i]
315}
316t.in3 307335960 9 3 100664 83 `
317 { x[NR] = $0 }
318END {
319 for (i in x)
320 if (x[i] ~ /shen/)
321 break
322 print i, x[i]
323}
324
325t.incr 307335960 9 3 100664 52 `
326{ ++i; --j; k++; l-- }
327END { print NR, i, j, k, l }
328t.incr2 307335960 9 3 100664 56 `
329{ s = 0
330 for (i=1; i <= NF; )
331 s += $(i++)
332 print s
333}
334t.incr3 307335960 9 3 100664 58 `
335{ s = 0
336 for (i=1; i <= NF; s += $(i++))
337 ;
338 print s
339}
340t.index 307335960 9 3 100664 144 `
341{ n = length
342 d = 0
343 for (i = 1; i <= n; i++)
344 if ((k = index($0, substr($0, i))) != i)
345 d = 1
346 if (d)
347 print $0, "has duplicate letters"
348}
349t.j.x 307335961 9 3 100664 55 `
350{i=i+sqrt($1); print i,sqrt($1)}
351END {print sqrt(i),i}
352
353t.longstr 307335984 9 3 100666 137 `
354BEGIN{
355x = "111111111122222222233333333334444444444555555555566666666667777777777888888888899999999990000000000"
356printf "%s\n", x
357exit
358}
359
360t.makef 307335961 9 3 100664 30 `
361{$3 = 2*$1; print $1, $2, $3}
362t.match 307335961 9 3 100664 15 `
363$2 ~ /ava|bwk/
364
365t.max 307335961 9 3 100664 58 `
366length > max { max = length; x = $0}
367END { print max, x }
368t.mod 307335961 9 3 100664 12 `
369NR % 2 == 1
370t.monotone 307335961 9 3 100664 112 `
371/^a?b?c?d?e?f?g?h?i?j?k?l?m?n?o?p?q?r?s?t?u?v?w?x?y?z?$|^z?y?x?w?v?u?t?s?r?q?p?o?n?m?l?k?j?i?h?g?f?e?d?c?b?a?$/
372t.nameval 307335961 9 3 100664 132 `
373 { if (amount[$2] == "")
374 name[++n] = $2
375 amount[$2] += $1
376 }
377END { for (i = 1; i <= n; i++)
378 print name[i], amount[name[i]]
379 }
380t.next 307335961 9 3 100664 29 `
381$1 > 5000 { next }
382{ print }
383
384t.not 307335961 9 3 100664 55 `
385$2 !~ /ava|bwk/
386!($1 < 2000)
387!($2 ~ /bwk/)
388!$2 ~ /bwk/
389
390t.ofmt 307335961 9 3 100664 34 `
391BEGIN {OFMT="%.5g"}
392 {print $1+0}
393t.ofs 307335961 9 3 100664 67 `
394BEGIN { OFS = " %% "; ORS = "##" }
395 { print $1, $2; print "#x\n" }
396
397t.pipe 307335962 9 3 100664 54 `
398BEGIN {print "read /usr/bwk/awk/t.pipe" | "mail bwk"}
399t.pp 307335962 9 3 100664 8 `
400/a/,/b/
401t.pp1 307335962 9 3 100664 87 `
402/bwk/,/bwk/ { print $2, $1 }
403/ava/,/ava/ { print $2, $1 }
404/pjw/,/pjw/ { print $2, $1 }
405
406t.pp2 307335962 9 3 100664 99 `
407/bwk/,/scj/ { print "1: ", $0 }
408/bwk/, /bsb/ { print "2: ", $0 }
409/mel/, /doug/ { print "3: ", $0 }
410
411t.printf 307335962 9 3 100664 82 `
412{
413 printf "%%: %s ... %s \t", $2, $1
414x = sprintf "%8d %10.10s", $1, $2
415 print x
416}
417t.quote 307335962 9 3 100664 21 `
418{print "\"" $1 "\""}
419
420t.re1 307335962 9 3 100664 98 `
421/[a-cg-j1-3]/ { print $0 " matches /[a-cg-j1-3]/" }
422/[^aeiou]/ { print $0 " matches /[^aeiou]/" }
423t.rec 307335962 9 3 100664 19 `
424{ print sqrt($1) }
425
426t.redir 307335962 9 3 100664 55 `
427$1%2==1 {print >"oddtemp"}
428$1%2==0 {print >"eventemp"}
429
430t.roff 307335962 9 3 100664 251 `
431NF > 0 {
432 for (i = 1; i <= NF; i++) {
433 n = length($i)
434 if (n + olen >= 60) {
435 print oline
436 olen = n
437 oline = $i
438 } else {
439 oline = oline " " $i
440 olen += n
441 }
442 }
443}
444
445NF == 0 {
446 print oline
447 olen = 0
448}
449
450END {
451 if (olen > 0)
452 print oline
453}
454
455t.sep 307335962 9 3 100664 90 `
456BEGIN { FS = "1"; print "field separator is", FS }
457NF>1 { print $0 " has " NF " fields" }
458t.seqno 307335962 9 3 100664 15 `
459{print NR, $0}
460
461t.split 307335962 9 3 100664 64 `
462BEGIN { z = "stuff" }
463{ split ($0, x); print x[3], x[2], x[1] }
464t.split2 307335962 9 3 100664 36 `
465{ split ($0, x); print x[2], x[1] }
466t.split9 307334948 9 3 100666 145 `
467{
468 n = split ($0, x, FS)
469 if (n != NF)
470 print "botch at ", NR, n, NF
471 for (i=1; i<=n; i++)
472 if ($i != x[i])
473 print "diff at ", i, x[i], $i
474}
475
476t.split9a 307336346 9 3 100666 164 `
477BEGIN { FS = "a" }
478{
479 n = split ($0, x, FS)
480 if (n != NF)
481 print "botch at ", NR, n, NF
482 for (i=1; i<=n; i++)
483 if ($i != x[i])
484 print "diff at ", i, x[i], $i
485}
486t.stately 307335962 9 3 100664 159 `
487/^(al|ak|az|ar|ca|co|ct|de|fl|ga|hi|io|il|in|ia|ks|ky|la|me|md|ma|mi|mn|ms|mo|mt|nb|nv|nh|nj|nm|ny|nc|nd|oh|ok|or|pa|ri|sc|sd|tn|tx|ut|vt|va|wa|wv|wi|-|wy)*$/
488
489t.strcmp 307335963 9 3 100664 42 `
490$2 >= "ava" && $2 <= "bwk" || $2 >= "pjw"
491t.strcmp1 307335963 9 3 100664 52 `
492$1 != 1 && $1 != 2 && $1 != 3 && $1 != 4 && $1 != 5
493t.substr 307335963 9 3 100664 61 `
494substr($2, 1, 1) ~ /[abc]/
495substr($2, length($2)) !~ /[a-z]/
496
497t.time 307335963 9 3 100664 96 `
498BEGIN {
499 FS = "-"
500}
501
502/ing$/ {
503 n++
504 s += length($NF)
505 print
506}
507
508END {
509 print n, s, s/n >"glop"
510}
511t.vf 307335983 9 3 100664 44 `
512BEGIN { i = 1 }
513{print $(i+i)}
514{print $(1)}
515t.vf1 307335983 9 3 100664 66 `
516{ print
517 i = 1
518 while (i <= NF) {
519 print " " $i
520 i = i + 1
521 }
522}
523t.vf3 307335984 9 3 100664 36 `
524BEGIN { i=1; j=2 }
525{$i = $j; print}
526t.x 307335984 9 3 100664 4 `
527/x/
528Compare 308460881 9 1 100777 165 `
529for i
530do
531 echo $i:
532 awk -f $i foo >junk1
533 a.out -f $i foo >junk2
534 if cmp -s junk1 junk2
535 then echo $i: good
536 else echo $i: BAD
537 fi
538 diff -b junk1 junk2 | ind
539done
540
541testall 307336168 9 3 100777 27 `
542Compare t.* >test.out 2>&1
543
544t.null0 312829527 9 1 100666 397 `
545BEGIN { FS = ":" }
546{ if (a) print "a", a
547 if (b == 0) print "b", b
548 if ( c == "0") print "c", c
549 if (d == "") print "d", d
550 if (e == 1-1) print "e", e
551}
552$1 == 0 {print "$1 = 0"}
553$1 == "0" {print "$1 = quoted 0"}
554$1 == "" {print "$1 = null string"}
555$5 == 0 {print "$5 = 0"}
556$5 == "0" {print "$5 = quoted 0"}
557$5 == "" {print "$5 = null string"}
558$1 == $3 {print "$1 = $3"}
559$5 == $6 {print "$5 = $6"}
560
561test.data 323961880 9 3 100666 1429 `
562/dev/rrp3:
56317379 mel
56416693 bwk
56516116 ken
56615713 srb
56711895 lem
56810409 scj
56910252 rhm
570 9853 shen
571 9748 a68
572 9492 sif
573 9190 pjw
574 8912 nls
575 8895 dmr
576 8491 cda
577 8372 bs
578 8252 llc
579 7450 mb
580 7360 ava
581 7273 jrv
582 7080 bin
583 7063 greg
584 6567 dict
585 6462 lck
586 6291 rje
587 6211 lwf
588 5671 dave
589 5373 jhc
590 5220 agf
591 5167 doug
592 5007 valerie
593 3963 jca
594 3895 bbs
595 3796 moh
596 3481 xchar
597 3200 tbl
598 2845 s
599 2774 tgs
600 2641 met
601 2566 jck
602 2511 port
603 2479 sue
604 2127 root
605 1989 bsb
606 1989 jeg
607 1933 eag
608 1801 pdj
609 1590 tpc
610 1385 cvw
611 1370 rwm
612 1316 avg
613 1205 eg
614 1194 jam
615 1153 dl
616 1150 lgm
617 1031 cmb
618 1018 jwr
619 950 gdb
620 931 marc
621 898 usg
622 865 ggr
623 822 daemon
624 803 mihalis
625 700 honey
626 624 tad
627 559 acs
628 541 uucp
629 523 raf
630 495 adh
631 456 kec
632 414 craig
633 386 donmac
634 375 jj
635 348 ravi
636 344 drw
637 327 stars
638 288 mrg
639 272 jcb
640 263 ralph
641 253 tom
642 251 sjb
643 248 haight
644 224 sharon
645 222 chuck
646 213 dsj
647 201 bill
648 184 god
649 176 sys
650 166 meh
651 163 jon
652 144 dan
653 143 fox
654 123 dale
655 116 kab
656 95 buz
657 80 asc
658 79 jas
659 79 trt
660 64 wsb
661 62 dwh
662 56 ktf
663 54 lr
664 47 dlc
665 45 dls
666 45 jwf
667 44 mash
668 43 ars
669 43 vgl
670 37 jfo
671 32 rab
672 31 pd
673 29 jns
674 25 spm
675 22 rob
676 15 egb
677 10 hm
678 10 mhb
679 6 aed
680 6 cpb
681 5 evp
682 4 ber
683 4 men
684 4 mitch
685 3 ast
686 3 jfr
687 3 lax
688 3 nel
689 2 blue
690 2 jfk
691 2 njas
692 1 122sec
693 1 ddwar
694 1 gopi
695 1 jk
696 1 learn
697 1 low
698 1 nac
699 1 sidor
700