!<arch> t.0 307335954 9 3 100664 23 ` {i = i+1; print i, NR} t.1.x 307335954 9 3 100664 32 ` {i="count" $1 $2; print i , $0} t.2.x 307335954 9 3 100664 31 ` {i=2; j=$3; $1=i;print i,j,$1} t.3 307335954 9 3 100664 23 ` $1 == "5" || $1 == "4" t.3.x 307335954 9 3 100664 50 ` { x = $1 while (x > 1) { print x x = x / 10 } } t.4 307335954 9 3 100664 21 ` $1 ~ /5/ || $1 ~ /4/ t.4.x 307335954 9 3 100664 18 ` {i=$(1); print i} t.5.x 307335954 9 3 100664 28 ` {$(1) = "xxx"; print $1,$0} t.6 307335954 9 3 100664 76 ` /a|b|c/ { i = $1 print while (i >= 1) { print " ", i i = i / 10 } } t.6.x 307335955 9 3 100664 14 ` {print NF,$0} t.6a 307335955 9 3 100664 64 ` /a|b|c/ { print for (i = $1; i >= 1; ) print " ", i /= 10 } t.6b 307335955 9 3 100664 65 ` /a|b|c/ { print for (i = $1; (i /= 10)>= 1; ) print " ", i } t.8.x 307335955 9 3 100664 15 ` {$2=$1; print} t.a 307335955 9 3 100666 130 ` {if (amount[$2] "" == "") item[num++] = $2; amount[$2] += $1 } END {for (i=0; i<num; i++) print item[i], amount[item[i]] } t.aeiou 307335955 9 3 100664 58 ` /^[^aeiouy]*[aeiou][^aeiouy][aeiouy][aeiouy]*[^aeiouy]*$/ t.aeiouy 307335955 9 3 100664 81 ` /^[^aeiouy]*a[^aeiouy]*e[^aeiouy]*i[^aeiouy]*o[^aeiouy]*u[^aeiouy]*y[^aeiouy]*$/ t.arith 307335955 9 3 100664 52 ` { print $1, $1+$1, $1-$1, $1 * $1, $1/$1, $1 % NR } t.array 307335955 9 3 100664 147 ` { x[NR] = $0 } END { i = 1 while (i <= NR) { print x[i] split (x[i], y) usage = y[1] name = y[2] print " ", name, usage i++ } } t.array1 307335955 9 3 100664 123 ` {for(i=1; i<=NF; i++) { if (x[$i] == "") y[n++] = $i x[$i]++ } } END { for (i=0; i<n; i++) print (y[i], x[y[i]]) } t.array2 307335955 9 3 100664 168 ` $2 ~ /^[a-l]/ { x["a"] = x["a"] + 1 } $2 ~ /^[m-z]/ { x["m"] = x["m"] + 1 } $2 !~ /^[a-z]/ { x["other"] = x["other"] + 1 } END { print NR, x["a"], x["m"], x["other"] } t.avg 307335955 9 3 100664 80 ` {s = s + $1; c = c + 1} END { print "sum=", s, " count=", c print "avg=", s/c } t.b.x 307335956 9 3 100664 36 ` {$6=":::" ; print $6; print NF, $0} t.be 307335956 9 3 100664 42 ` BEGIN { print FILENAME } END { print NR } t.break 307335956 9 3 100664 91 ` { for (i=1; i <= NF; i++) if ($i ~ /^[a-z]+$/) { print $i " is alphabetic" break } } t.break1 307335956 9 3 100664 135 ` { x[NR] = $0 } END { for (i = 1; i <= NR; i++) { print i, x[i] if (x[i] ~ /shen/) break } print "got here" print i, x[i] } t.break2 307335956 9 3 100664 122 ` { x[NR] = $0 } END { for (i in x) { print i, x[i] if (x[i] ~ /shen/) break } print "got here" print i, x[i] } t.break3 307335956 9 3 100666 116 ` { for (i = 1; i <= NF; i++) { for (j = 1; j <= NF; j++) break; print "inner", i, j } print "outer", i, j } t.bug1 307335985 9 3 100666 103 ` # this program fails if awk is created without separate I&D # prints garbage if no $3 { print $1, $3 } t.cat 307335956 9 3 100664 114 ` {print $2 " " $1} {print $1 " " "is", $2} {print $2 FS "is" FS $1} {print length($1 $2), length($1) + length($2)} t.cat1 307335957 9 3 100664 38 ` {print x $0} # should precede by zero t.cat2 307335957 9 3 100664 21 ` {$1 = $1 "*"; print} t.cmp 307335957 9 3 100664 8 ` $2 > $1 t.coerce 307335957 9 3 100664 47 ` END { print i, NR if (i < NR) print i, NR } t.comment 307335957 9 3 100664 112 ` # this is a comment line # so is this /#/ { print "this one has a # in it: " $0 # comment print "again:" $0 } t.comment1 307335957 9 3 100664 88 ` #comment # BEGIN { x = 1 } /abc/ { print $0 } #comment END { print NR } #comment t.contin 307335957 9 3 100664 130 ` { for (i = 1; i <= NF; i++) { if ($i ~ /^[0-9]+$/) continue; print $i, " is non-numeric" next } print $0, "is all numeric" } t.count 307335957 9 3 100664 17 ` END { print NR } t.cum 307335957 9 3 100664 38 ` {i = i + $1; print i} END { print i } t.d.x 307335958 9 3 100664 43 ` BEGIN {FS=":" ; OFS=":"} {print NF " ",$0} t.e 307335958 9 3 100664 23 ` $1 < 10 || $2 ~ /bwk/ t.else 307335958 9 3 100664 46 ` { if($1>1000) print "yes" else print "no" } t.exit 307335958 9 3 100664 32 ` { print } $1 < 5000 { exit NR } t.f 307335958 9 3 100664 15 ` {print $2, $1} t.f.x 307335958 9 3 100664 26 ` $1>0 {print $1, sqrt($1)} t.f0 307335959 9 3 100664 20 ` $1 ~ /x/ {print $0} t.f1 307335959 9 3 100664 16 ` {$1 = 1; print} t.f2 307335959 9 3 100664 19 ` {$1 = 1; print $0} t.f3 307335959 9 3 100664 17 ` {$1 = NR; print} t.f4 307335959 9 3 100664 20 ` {$1 = NR; print $0} t.for 307335959 9 3 100664 39 ` { for (i=1; i<=NF; i++) print i, $i } t.for1 307335959 9 3 100664 68 ` { i = 1 for (;;) { if (i > NF) next print i, $i i++ } } t.for2 307335960 9 3 100664 61 ` { for (i=1;;i++) { if (i > NF) next print i, $i } } t.format4 307335985 9 3 100664 127 ` BEGIN { text=sprintf ("%125s", "x") print length (text) print text xxx=substr (text,1,105) print length (xxx) print xxx exit } t.func 307335960 9 3 100664 73 ` { print $1, length($1), log($1), sqrt($1), int(sqrt($1)), exp($1 % 10) } t.getline 307335984 9 3 100666 117 ` { x = $1 for (i = 1; i <= 3; i++) if (getline) x = x " " $1 print x x = "" } END { if (x != "") print x } t.i.x 307335960 9 3 100664 52 ` {i=i+log($1); print i,log($1)} END {print exp(i),i} t.if 307335960 9 3 100664 21 ` {if($1 || $2) print} t.in 307335960 9 3 100664 98 ` BEGIN { x["apple"] = 1; x["orange"] = 2; x["lemon"] = 3; for (i in x) print i, x[i] exit } t.in1 307335960 9 3 100664 126 ` { if (amount[$2] == "") name[++n] = $2 amount[$2] += $1 } END { for (i in name) print i, name[i], amount[name[i]] } t.in2 307335960 9 3 100664 68 ` { x[substr($2, 1, 1)] += $1 } END { for (i in x) print i, x[i] } t.in3 307335960 9 3 100664 83 ` { x[NR] = $0 } END { for (i in x) if (x[i] ~ /shen/) break print i, x[i] } t.incr 307335960 9 3 100664 52 ` { ++i; --j; k++; l-- } END { print NR, i, j, k, l } t.incr2 307335960 9 3 100664 56 ` { s = 0 for (i=1; i <= NF; ) s += $(i++) print s } t.incr3 307335960 9 3 100664 58 ` { s = 0 for (i=1; i <= NF; s += $(i++)) ; print s } t.index 307335960 9 3 100664 144 ` { n = length d = 0 for (i = 1; i <= n; i++) if ((k = index($0, substr($0, i))) != i) d = 1 if (d) print $0, "has duplicate letters" } t.j.x 307335961 9 3 100664 55 ` {i=i+sqrt($1); print i,sqrt($1)} END {print sqrt(i),i} t.longstr 307335984 9 3 100666 137 ` BEGIN{ x = "111111111122222222233333333334444444444555555555566666666667777777777888888888899999999990000000000" printf "%s\n", x exit } t.makef 307335961 9 3 100664 30 ` {$3 = 2*$1; print $1, $2, $3} t.match 307335961 9 3 100664 15 ` $2 ~ /ava|bwk/ t.max 307335961 9 3 100664 58 ` length > max { max = length; x = $0} END { print max, x } t.mod 307335961 9 3 100664 12 ` NR % 2 == 1 t.monotone 307335961 9 3 100664 112 ` /^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?$/ t.nameval 307335961 9 3 100664 132 ` { if (amount[$2] == "") name[++n] = $2 amount[$2] += $1 } END { for (i = 1; i <= n; i++) print name[i], amount[name[i]] } t.next 307335961 9 3 100664 29 ` $1 > 5000 { next } { print } t.not 307335961 9 3 100664 55 ` $2 !~ /ava|bwk/ !($1 < 2000) !($2 ~ /bwk/) !$2 ~ /bwk/ t.ofmt 307335961 9 3 100664 34 ` BEGIN {OFMT="%.5g"} {print $1+0} t.ofs 307335961 9 3 100664 67 ` BEGIN { OFS = " %% "; ORS = "##" } { print $1, $2; print "#x\n" } t.pipe 307335962 9 3 100664 54 ` BEGIN {print "read /usr/bwk/awk/t.pipe" | "mail bwk"} t.pp 307335962 9 3 100664 8 ` /a/,/b/ t.pp1 307335962 9 3 100664 87 ` /bwk/,/bwk/ { print $2, $1 } /ava/,/ava/ { print $2, $1 } /pjw/,/pjw/ { print $2, $1 } t.pp2 307335962 9 3 100664 99 ` /bwk/,/scj/ { print "1: ", $0 } /bwk/, /bsb/ { print "2: ", $0 } /mel/, /doug/ { print "3: ", $0 } t.printf 307335962 9 3 100664 82 ` { printf "%%: %s ... %s \t", $2, $1 x = sprintf "%8d %10.10s", $1, $2 print x } t.quote 307335962 9 3 100664 21 ` {print "\"" $1 "\""} t.re1 307335962 9 3 100664 98 ` /[a-cg-j1-3]/ { print $0 " matches /[a-cg-j1-3]/" } /[^aeiou]/ { print $0 " matches /[^aeiou]/" } t.rec 307335962 9 3 100664 19 ` { print sqrt($1) } t.redir 307335962 9 3 100664 55 ` $1%2==1 {print >"oddtemp"} $1%2==0 {print >"eventemp"} t.roff 307335962 9 3 100664 251 ` NF > 0 { for (i = 1; i <= NF; i++) { n = length($i) if (n + olen >= 60) { print oline olen = n oline = $i } else { oline = oline " " $i olen += n } } } NF == 0 { print oline olen = 0 } END { if (olen > 0) print oline } t.sep 307335962 9 3 100664 90 ` BEGIN { FS = "1"; print "field separator is", FS } NF>1 { print $0 " has " NF " fields" } t.seqno 307335962 9 3 100664 15 ` {print NR, $0} t.split 307335962 9 3 100664 64 ` BEGIN { z = "stuff" } { split ($0, x); print x[3], x[2], x[1] } t.split2 307335962 9 3 100664 36 ` { split ($0, x); print x[2], x[1] } t.split9 307334948 9 3 100666 145 ` { n = split ($0, x, FS) if (n != NF) print "botch at ", NR, n, NF for (i=1; i<=n; i++) if ($i != x[i]) print "diff at ", i, x[i], $i } t.split9a 307336346 9 3 100666 164 ` BEGIN { FS = "a" } { n = split ($0, x, FS) if (n != NF) print "botch at ", NR, n, NF for (i=1; i<=n; i++) if ($i != x[i]) print "diff at ", i, x[i], $i } t.stately 307335962 9 3 100664 159 ` /^(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)*$/ t.strcmp 307335963 9 3 100664 42 ` $2 >= "ava" && $2 <= "bwk" || $2 >= "pjw" t.strcmp1 307335963 9 3 100664 52 ` $1 != 1 && $1 != 2 && $1 != 3 && $1 != 4 && $1 != 5 t.substr 307335963 9 3 100664 61 ` substr($2, 1, 1) ~ /[abc]/ substr($2, length($2)) !~ /[a-z]/ t.time 307335963 9 3 100664 96 ` BEGIN { FS = "-" } /ing$/ { n++ s += length($NF) print } END { print n, s, s/n >"glop" } t.vf 307335983 9 3 100664 44 ` BEGIN { i = 1 } {print $(i+i)} {print $(1)} t.vf1 307335983 9 3 100664 66 ` { print i = 1 while (i <= NF) { print " " $i i = i + 1 } } t.vf3 307335984 9 3 100664 36 ` BEGIN { i=1; j=2 } {$i = $j; print} t.x 307335984 9 3 100664 4 ` /x/ Compare 308460881 9 1 100777 165 ` for i do echo $i: awk -f $i foo >junk1 a.out -f $i foo >junk2 if cmp -s junk1 junk2 then echo $i: good else echo $i: BAD fi diff -b junk1 junk2 | ind done testall 307336168 9 3 100777 27 ` Compare t.* >test.out 2>&1 t.null0 312829527 9 1 100666 397 ` BEGIN { FS = ":" } { if (a) print "a", a if (b == 0) print "b", b if ( c == "0") print "c", c if (d == "") print "d", d if (e == 1-1) print "e", e } $1 == 0 {print "$1 = 0"} $1 == "0" {print "$1 = quoted 0"} $1 == "" {print "$1 = null string"} $5 == 0 {print "$5 = 0"} $5 == "0" {print "$5 = quoted 0"} $5 == "" {print "$5 = null string"} $1 == $3 {print "$1 = $3"} $5 == $6 {print "$5 = $6"} test.data 323961880 9 3 100666 1429 ` /dev/rrp3: 17379 mel 16693 bwk 16116 ken 15713 srb 11895 lem 10409 scj 10252 rhm 9853 shen 9748 a68 9492 sif 9190 pjw 8912 nls 8895 dmr 8491 cda 8372 bs 8252 llc 7450 mb 7360 ava 7273 jrv 7080 bin 7063 greg 6567 dict 6462 lck 6291 rje 6211 lwf 5671 dave 5373 jhc 5220 agf 5167 doug 5007 valerie 3963 jca 3895 bbs 3796 moh 3481 xchar 3200 tbl 2845 s 2774 tgs 2641 met 2566 jck 2511 port 2479 sue 2127 root 1989 bsb 1989 jeg 1933 eag 1801 pdj 1590 tpc 1385 cvw 1370 rwm 1316 avg 1205 eg 1194 jam 1153 dl 1150 lgm 1031 cmb 1018 jwr 950 gdb 931 marc 898 usg 865 ggr 822 daemon 803 mihalis 700 honey 624 tad 559 acs 541 uucp 523 raf 495 adh 456 kec 414 craig 386 donmac 375 jj 348 ravi 344 drw 327 stars 288 mrg 272 jcb 263 ralph 253 tom 251 sjb 248 haight 224 sharon 222 chuck 213 dsj 201 bill 184 god 176 sys 166 meh 163 jon 144 dan 143 fox 123 dale 116 kab 95 buz 80 asc 79 jas 79 trt 64 wsb 62 dwh 56 ktf 54 lr 47 dlc 45 dls 45 jwf 44 mash 43 ars 43 vgl 37 jfo 32 rab 31 pd 29 jns 25 spm 22 rob 15 egb 10 hm 10 mhb 6 aed 6 cpb 5 evp 4 ber 4 men 4 mitch 3 ast 3 jfr 3 lax 3 nel 2 blue 2 jfk 2 njas 1 122sec 1 ddwar 1 gopi 1 jk 1 learn 1 low 1 nac 1 sidor