├── .github ├── FUNDING.yml └── workflows │ └── tests.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── docs ├── cover.md ├── cover.png └── csv.md ├── go.mod ├── goawk.go ├── goawk_test.go ├── internal ├── ast │ ├── ast.go │ ├── specialvars.go │ ├── specialvars_test.go │ └── walk.go ├── compiler │ ├── compiler.go │ ├── disassembler.go │ ├── disassembler_test.go │ ├── opcode_string.go │ └── opcodes.go ├── cover │ ├── cover.go │ └── cover_test.go ├── parseutil │ ├── filereader.go │ └── filereader_test.go └── resolver │ ├── resolve.go │ ├── toposort.go │ └── toposort_test.go ├── interp ├── csvreader_test.go ├── example_test.go ├── functions.go ├── fuzz_test.go ├── fuzz_unexported_test.go ├── interp.go ├── interp_test.go ├── io.go ├── iostream.go ├── iostream_test.go ├── newexecute.go ├── newexecute_test.go ├── value.go └── vm.go ├── lexer ├── lexer.go ├── lexer_test.go └── token.go ├── parser ├── parser.go └── parser_test.go ├── scripts ├── benchmark.sh ├── benchmark_awks.py ├── benchstat.sh ├── csvbench │ ├── count.py │ ├── count │ │ └── main.go │ ├── csvbench.sh │ ├── write.py │ └── write │ │ └── main.go ├── fuzz_input.sh ├── fuzz_source.sh └── make_binaries.sh └── testdata ├── README ├── awc.awk ├── cover ├── a1.awk ├── a1_a2_covermode_count.awk ├── a1_annotation_data.txt ├── a1_covermode_set.awk ├── a2.awk ├── a2_annotation_data.txt ├── a2_covermode_count.awk ├── a3.awk ├── a3_annotation_data.txt ├── a3_covermode_set.awk ├── test_1file2runs_set.cov ├── test_1file2runs_set_truncated.cov ├── test_2file2runs_count.cov ├── test_2file2runs_count_truncated.cov ├── test_a2a1_count.cov ├── test_a2a1_set.cov ├── test_count.cov └── test_set.cov ├── csv ├── 1.csv ├── 2.csv ├── address5.csv ├── fields.csv ├── nz-schools.csv ├── states.csv └── states.psv ├── filename ├── 10 └── 10x ├── foo.td ├── g.1 ├── g.2 ├── g.3 ├── g.4 ├── g.5 ├── g.6 ├── gawk ├── addcomma.awk ├── addcomma.in ├── addcomma.ok ├── anchgsub.awk ├── anchgsub.in ├── anchgsub.ok ├── anchor.awk ├── anchor.in ├── anchor.ok ├── argarray.awk ├── argarray.in ├── argarray.ok ├── arrayind3.awk ├── arrayind3.ok ├── arrayparm.awk ├── arrayparm.ok ├── arrayprm2.awk ├── arrayprm2.ok ├── arrayprm3.awk ├── arrayprm3.ok ├── arrayref.awk ├── arrayref.ok ├── arrymem1.awk ├── arrymem1.ok ├── arryref2.awk ├── arryref2.ok ├── arryref3.awk ├── arryref3.ok ├── arryref4.awk ├── arryref4.ok ├── arryref5.awk ├── arryref5.ok ├── arynasty.awk ├── arynasty.ok ├── aryprm1.awk ├── aryprm1.ok ├── aryprm3.awk ├── aryprm3.ok ├── aryprm4.awk ├── aryprm4.ok ├── aryprm5.awk ├── aryprm5.ok ├── aryprm6.awk ├── aryprm6.ok ├── aryprm7.awk ├── aryprm7.ok ├── aryprm8.awk ├── aryprm8.ok ├── aryprm9.awk ├── aryprm9.ok ├── arysubnm.awk ├── arysubnm.ok ├── aryunasgn.awk ├── aryunasgn.ok ├── asgext.awk ├── asgext.in ├── asgext.ok ├── assignnumfield.awk ├── assignnumfield.in ├── assignnumfield.ok ├── back89.awk ├── back89.ok ├── backgsub.awk ├── backgsub.in ├── backgsub.ok ├── badassign1.awk ├── badassign1.ok ├── badbuild.awk ├── badbuild.in ├── badbuild.ok ├── callparam.awk ├── callparam.ok ├── childin.awk ├── childin.in ├── childin.ok ├── clobber.awk ├── clobber.ok ├── closebad.awk ├── closebad.ok ├── compare.awk ├── compare.in ├── compare.ok ├── compare2.awk ├── compare2.ok ├── concat1.awk ├── concat1.in ├── concat1.ok ├── concat2.awk ├── concat2.ok ├── concat3.awk ├── concat3.ok ├── concat4.awk ├── concat4.in ├── concat4.ok ├── concat5.awk ├── concat5.ok ├── convfmt.awk ├── convfmt.ok ├── datanonl.awk ├── datanonl.in ├── datanonl.ok ├── defref.awk ├── defref.ok ├── delargv.awk ├── delargv.ok ├── delarpm2.awk ├── delarpm2.ok ├── delfunc.awk ├── delfunc.ok ├── dfastress.awk ├── dfastress.ok ├── dynlj.awk ├── dynlj.ok ├── eofsplit.awk ├── eofsplit.ok ├── exit2.awk ├── exit2.ok ├── exitval2.awk ├── exitval2.ok ├── fcall_exit.awk ├── fcall_exit.ok ├── fcall_exit2.awk ├── fcall_exit2.in ├── fcall_exit2.ok ├── fldchg.awk ├── fldchg.in ├── fldchg.ok ├── fldchgnf.awk ├── fldchgnf.in ├── fldchgnf.ok ├── fldterm.awk ├── fldterm.in ├── fldterm.ok ├── fnamedat.awk ├── fnamedat.in ├── fnamedat.ok ├── fnarray.awk ├── fnarray.ok ├── fnarray2.awk ├── fnarray2.in ├── fnarray2.ok ├── fnaryscl.awk ├── fnaryscl.ok ├── fnasgnm.awk ├── fnasgnm.in ├── fnasgnm.ok ├── fnmisc.awk ├── fnmisc.ok ├── forref.awk ├── forref.ok ├── forsimp.awk ├── forsimp.ok ├── fsbs.awk ├── fsbs.in ├── fsbs.ok ├── fsnul1.awk ├── fsnul1.in ├── fsnul1.ok ├── fsrs.awk ├── fsrs.in ├── fsrs.ok ├── fsspcoln.awk ├── fsspcoln.in ├── fsspcoln.ok ├── fstabplus.awk ├── fstabplus.in ├── fstabplus.ok ├── funlen.awk ├── funlen.in ├── funlen.ok ├── funsemnl.awk ├── funsemnl.ok ├── funsmnam.awk ├── funsmnam.ok ├── funstack.awk ├── funstack.in ├── funstack.ok ├── getline.awk ├── getline.in ├── getline.ok ├── getline2.awk ├── getline2.in ├── getline2.ok ├── getline3.awk ├── getline3.ok ├── getline4.awk ├── getline4.in ├── getline4.ok ├── getline5.awk ├── getline5.ok ├── getlnbuf.awk ├── getlnbuf.in ├── getlnbuf.ok ├── getnr2tb.awk ├── getnr2tb.in ├── getnr2tb.ok ├── getnr2tm.awk ├── getnr2tm.in ├── getnr2tm.ok ├── gsubasgn.awk ├── gsubasgn.ok ├── gsubtest.awk ├── gsubtest.ok ├── gsubtst2.awk ├── gsubtst2.ok ├── gsubtst3.awk ├── gsubtst3.in ├── gsubtst3.ok ├── gsubtst4.awk ├── gsubtst4.ok ├── gsubtst5.awk ├── gsubtst5.in ├── gsubtst5.ok ├── gsubtst6.awk ├── gsubtst6.ok ├── gsubtst7.awk ├── gsubtst7.in ├── gsubtst7.ok ├── gsubtst8.awk ├── gsubtst8.in ├── gsubtst8.ok ├── hex.awk ├── hex.ok ├── hex2.awk ├── hex2.in ├── hex2.ok ├── hsprint.awk ├── hsprint.ok ├── inpref.awk ├── inpref.in ├── inpref.ok ├── inputred.awk ├── inputred.ok ├── intest.awk ├── intest.ok ├── intprec.awk ├── intprec.ok ├── iobug1.awk ├── iobug1.ok ├── leaddig.awk ├── leaddig.ok ├── leadnl.awk ├── leadnl.in ├── leadnl.ok ├── litoct.awk ├── litoct.in ├── litoct.ok ├── longsub.awk ├── longsub.in ├── longsub.ok ├── longwrds.awk ├── longwrds.in ├── longwrds.ok ├── manglprm.awk ├── manglprm.in ├── manglprm.ok ├── math.awk ├── math.ok ├── minusstr.awk ├── minusstr.ok ├── mmap8k.awk ├── mmap8k.in ├── mmap8k.ok ├── nasty.awk ├── nasty.ok ├── nasty2.awk ├── nasty2.ok ├── negexp.awk ├── negexp.ok ├── negrange.awk ├── negrange.ok ├── nested.awk ├── nested.in ├── nested.ok ├── nfldstr.awk ├── nfldstr.in ├── nfldstr.ok ├── nfloop.awk ├── nfloop.ok ├── nfneg.awk ├── nfneg.ok ├── nfset.awk ├── nfset.in ├── nfset.ok ├── nlfldsep.awk ├── nlfldsep.in ├── nlfldsep.ok ├── nlinstr.awk ├── nlinstr.in ├── nlinstr.ok ├── nlstrina.awk ├── nlstrina.ok ├── noeffect.awk ├── noeffect.ok ├── nofmtch.awk ├── nofmtch.ok ├── noloop1.awk ├── noloop1.in ├── noloop1.ok ├── noloop2.awk ├── noloop2.in ├── noloop2.ok ├── nonl.awk ├── nonl.in ├── nonl.ok ├── noparms.awk ├── noparms.ok ├── nulinsrc.awk ├── nulinsrc.ok ├── nulrsend.awk ├── nulrsend.in ├── nulrsend.ok ├── numindex.awk ├── numindex.in ├── numindex.ok ├── numrange.awk ├── numrange.ok ├── numstr1.awk ├── numstr1.ok ├── numsubstr.awk ├── numsubstr.in ├── numsubstr.ok ├── octsub.awk ├── octsub.ok ├── ofmt.awk ├── ofmt.in ├── ofmt.ok ├── ofmta.awk ├── ofmta.ok ├── ofmtbig.awk ├── ofmtbig.in ├── ofmtbig.ok ├── ofmtfidl.awk ├── ofmtfidl.in ├── ofmtfidl.ok ├── ofmts.awk ├── ofmts.in ├── ofmts.ok ├── ofmtstrnum.awk ├── ofmtstrnum.ok ├── ofs1.awk ├── ofs1.in ├── ofs1.ok ├── onlynl.awk ├── onlynl.in ├── onlynl.ok ├── opasnidx.awk ├── opasnidx.ok ├── opasnslf.awk ├── opasnslf.ok ├── paramasfunc1.awk ├── paramasfunc1.ok ├── paramasfunc2.awk ├── paramasfunc2.ok ├── paramdup.awk ├── paramdup.ok ├── paramtyp.awk ├── paramtyp.ok ├── paramuninitglobal.awk ├── paramuninitglobal.ok ├── parse1.awk ├── parse1.in ├── parse1.ok ├── parsefld.awk ├── parsefld.in ├── parsefld.ok ├── parseme.awk ├── parseme.ok ├── pcntplus.awk ├── pcntplus.ok ├── posix2008sub.awk ├── posix2008sub.ok ├── prdupval.awk ├── prdupval.in ├── prdupval.ok ├── prec.awk ├── prec.ok ├── printf1.awk ├── printf1.ok ├── printfchar.awk ├── printfchar.ok ├── prmarscl.awk ├── prmarscl.ok ├── prmreuse.awk ├── prmreuse.ok ├── prt1eval.awk ├── prt1eval.ok ├── prtoeval.awk ├── prtoeval.ok ├── rand.awk ├── rand.ok ├── range1.awk ├── range1.in ├── range1.ok ├── readbuf.awk ├── readbuf.ok ├── rebuild.awk ├── rebuild.in ├── rebuild.ok ├── redfilnm.awk ├── redfilnm.in ├── redfilnm.ok ├── regeq.awk ├── regeq.in ├── regeq.ok ├── regexpbrack.awk ├── regexpbrack.in ├── regexpbrack.ok ├── regexpbrack2.awk ├── regexpbrack2.in ├── regexpbrack2.ok ├── regexprange.awk ├── regexprange.ok ├── regrange.awk ├── regrange.ok ├── reparse.awk ├── reparse.in ├── reparse.ok ├── resplit.awk ├── resplit.in ├── resplit.ok ├── rri1.awk ├── rri1.in ├── rri1.ok ├── rs.awk ├── rs.in ├── rs.ok ├── rscompat.awk ├── rscompat.in ├── rscompat.ok ├── rsgetline.awk ├── rsgetline.in ├── rsgetline.ok ├── rsnul1nl.awk ├── rsnul1nl.in ├── rsnul1nl.ok ├── rsnullre.awk ├── rsnullre.in ├── rsnullre.ok ├── rsnulw.awk ├── rsnulw.in ├── rsnulw.ok ├── rsstart1.awk ├── rsstart1.in ├── rsstart1.ok ├── rsstart2.awk ├── rsstart2.in ├── rsstart2.ok ├── rstest1.awk ├── rstest1.ok ├── rstest2.awk ├── rstest2.ok ├── rstest3.awk ├── rstest3.ok ├── rstest4.awk ├── rstest4.ok ├── rstest5.awk ├── rstest5.ok ├── rstest6.awk ├── rstest6.in ├── rstest6.ok ├── rswhite.awk ├── rswhite.in ├── rswhite.ok ├── scalar.awk ├── scalar.ok ├── sclforin.awk ├── sclforin.ok ├── sclifin.awk ├── sclifin.ok ├── setrec0.awk ├── setrec0.in ├── setrec0.ok ├── setrec1.awk ├── setrec1.ok ├── sigpipe1.awk ├── sigpipe1.ok ├── spacere.awk ├── spacere.ok ├── splitargv.awk ├── splitargv.in ├── splitargv.ok ├── splitarr.awk ├── splitarr.ok ├── splitdef.awk ├── splitdef.ok ├── splitvar.awk ├── splitvar.in ├── splitvar.ok ├── splitwht.awk ├── splitwht.ok ├── status-close.awk ├── status-close.ok ├── strcat1.awk ├── strcat1.ok ├── strnum1.awk ├── strnum1.ok ├── strnum2.awk ├── strnum2.ok ├── strtod.awk ├── strtod.in ├── strtod.ok ├── subamp.awk ├── subamp.in ├── subamp.ok ├── subback.awk ├── subback.in ├── subback.ok ├── subi18n.awk ├── subi18n.ok ├── subsepnm.awk ├── subsepnm.ok ├── subslash.awk ├── subslash.ok ├── substr.awk ├── substr.ok ├── swaplns.awk ├── swaplns.in ├── swaplns.ok ├── synerr1.awk ├── synerr1.ok ├── synerr2.awk ├── synerr2.ok ├── tailrecurse.awk ├── tailrecurse.ok ├── tradanch.awk ├── tradanch.in ├── tradanch.ok ├── tweakfld.awk ├── tweakfld.in ├── tweakfld.ok ├── uninit2.awk ├── uninit2.ok ├── uninit3.awk ├── uninit3.ok ├── uninit4.awk ├── uninit4.ok ├── uninit5.awk ├── uninit5.ok ├── uninitialized.awk ├── uninitialized.ok ├── unterm.awk ├── unterm.ok ├── uparrfs.awk ├── uparrfs.in ├── uparrfs.ok ├── uplus.awk ├── uplus.ok ├── wideidx.awk ├── wideidx.in ├── wideidx.ok ├── wideidx2.awk ├── wideidx2.ok ├── widesub.awk ├── widesub.ok ├── widesub2.awk ├── widesub2.ok ├── widesub3.awk ├── widesub3.in ├── widesub3.ok ├── widesub4.awk ├── widesub4.ok ├── wjposer1.awk ├── wjposer1.in ├── wjposer1.ok ├── zero2.awk ├── zero2.ok ├── zeroe0.awk ├── zeroe0.ok ├── zeroflag.awk └── zeroflag.ok ├── other └── gron.awk ├── output ├── p.1 ├── p.10 ├── p.11 ├── p.12 ├── p.13 ├── p.14 ├── p.15 ├── p.16 ├── p.17 ├── p.18 ├── p.19 ├── p.2 ├── p.20 ├── p.21 ├── p.21a ├── p.22 ├── p.23 ├── p.24 ├── p.25 ├── p.26 ├── p.26a ├── p.27 ├── p.28 ├── p.29 ├── p.3 ├── p.30 ├── p.31 ├── p.32 ├── p.33 ├── p.34 ├── p.35 ├── p.36 ├── p.37 ├── p.38 ├── p.39 ├── p.4 ├── p.40 ├── p.41 ├── p.42 ├── p.43 ├── p.44 ├── p.45 ├── p.46 ├── p.47 ├── p.48 ├── p.48a ├── p.48b ├── p.49 ├── p.5 ├── p.50 ├── p.51 ├── p.52 ├── p.5a ├── p.6 ├── p.7 ├── p.8 ├── p.9 ├── p.table ├── t.0 ├── t.0a ├── t.1 ├── t.1.x ├── t.2 ├── t.2.x ├── t.3 ├── t.3.x ├── t.4 ├── t.4.x ├── t.5.x ├── t.6 ├── t.6.x ├── t.6a ├── t.6b ├── t.8.x ├── t.8.y ├── t.NF ├── t.a ├── t.addops ├── t.aeiou ├── t.aeiouy ├── t.arith ├── t.array ├── t.array1 ├── t.array2 ├── t.assert ├── t.avg ├── t.b.x ├── t.be ├── t.beginexit ├── t.beginnext ├── t.break ├── t.break1 ├── t.break2 ├── t.break3 ├── t.bug1 ├── t.builtins ├── t.cat ├── t.cat1 ├── t.cat2 ├── t.cmp ├── t.coerce ├── t.coerce2 ├── t.comment ├── t.comment1 ├── t.concat ├── t.cond ├── t.contin ├── t.count ├── t.crlf ├── t.cum ├── t.d.x ├── t.delete1 ├── t.delete2 ├── t.delete3 ├── t.do ├── t.e ├── t.else ├── t.exit ├── t.exit1 ├── t.f ├── t.f.x ├── t.f0 ├── t.f1 ├── t.f2 ├── t.f3 ├── t.f4 ├── t.for ├── t.for1 ├── t.for2 ├── t.for3 ├── t.format4 ├── t.fun ├── t.fun0 ├── t.fun1 ├── t.fun2 ├── t.fun3 ├── t.fun4 ├── t.fun5 ├── t.getval ├── t.gsub ├── t.gsub1 ├── t.gsub3 ├── t.gsub4 ├── t.i.x ├── t.if ├── t.in ├── t.in1 ├── t.in2 ├── t.in3 ├── t.incr ├── t.incr2 ├── t.incr3 ├── t.index ├── t.intest ├── t.intest2 ├── t.j.x ├── t.longstr ├── t.makef ├── t.match ├── t.match1 ├── t.max ├── t.mod ├── t.monotone ├── t.nameval ├── t.next ├── t.not ├── t.null0 ├── t.ofmt ├── t.ofs ├── t.ors ├── t.pat ├── t.pipe ├── t.pp ├── t.pp1 ├── t.pp2 ├── t.printf ├── t.printf2 ├── t.quote ├── t.randk ├── t.re1 ├── t.re1a ├── t.re2 ├── t.re3 ├── t.re4 ├── t.re5 ├── t.re7 ├── t.reFS ├── t.rec ├── t.reg ├── t.roff ├── t.sep ├── t.seqno ├── t.set0 ├── t.set0a ├── t.set0b ├── t.set1 ├── t.set2 ├── t.set3 ├── t.split2 ├── t.split2a ├── t.split3 ├── t.split4 ├── t.split8 ├── t.split9 ├── t.split9a ├── t.stately ├── t.strcmp ├── t.strcmp1 ├── t.strnum ├── t.sub1 ├── t.sub2 ├── t.sub3 ├── t.substr ├── t.substr1 ├── t.time ├── t.vf ├── t.vf1 ├── t.vf2 ├── t.vf3 └── t.x ├── p.1 ├── p.10 ├── p.11 ├── p.12 ├── p.13 ├── p.14 ├── p.15 ├── p.16 ├── p.17 ├── p.18 ├── p.19 ├── p.2 ├── p.20 ├── p.21 ├── p.21a ├── p.22 ├── p.23 ├── p.24 ├── p.25 ├── p.26 ├── p.26a ├── p.27 ├── p.28 ├── p.29 ├── p.3 ├── p.30 ├── p.31 ├── p.32 ├── p.33 ├── p.34 ├── p.35 ├── p.36 ├── p.37 ├── p.38 ├── p.39 ├── p.4 ├── p.40 ├── p.41 ├── p.42 ├── p.43 ├── p.44 ├── p.45 ├── p.46 ├── p.47 ├── p.48 ├── p.48a ├── p.48b ├── p.49 ├── p.5 ├── p.50 ├── p.51 ├── p.52 ├── p.5a ├── p.6 ├── p.7 ├── p.8 ├── p.9 ├── p.table ├── parseerror ├── bad.awk └── good.awk ├── t.0 ├── t.0a ├── t.1 ├── t.1.x ├── t.2 ├── t.2.x ├── t.3 ├── t.3.x ├── t.4 ├── t.4.x ├── t.5.x ├── t.6 ├── t.6.x ├── t.6a ├── t.6b ├── t.8.x ├── t.8.y ├── t.NF ├── t.a ├── t.addops ├── t.aeiou ├── t.aeiouy ├── t.arith ├── t.array ├── t.array1 ├── t.array2 ├── t.assert ├── t.avg ├── t.b.x ├── t.be ├── t.beginexit ├── t.beginnext ├── t.break ├── t.break1 ├── t.break2 ├── t.break3 ├── t.bug1 ├── t.builtins ├── t.cat ├── t.cat1 ├── t.cat2 ├── t.cmp ├── t.coerce ├── t.coerce2 ├── t.comment ├── t.comment1 ├── t.concat ├── t.cond ├── t.contin ├── t.count ├── t.crlf ├── t.cum ├── t.d.x ├── t.delete1 ├── t.delete2 ├── t.delete3 ├── t.do ├── t.e ├── t.else ├── t.exit ├── t.exit1 ├── t.f ├── t.f.x ├── t.f0 ├── t.f1 ├── t.f2 ├── t.f3 ├── t.f4 ├── t.for ├── t.for1 ├── t.for2 ├── t.for3 ├── t.format4 ├── t.fun ├── t.fun0 ├── t.fun1 ├── t.fun2 ├── t.fun3 ├── t.fun4 ├── t.fun5 ├── t.getval ├── t.gsub ├── t.gsub1 ├── t.gsub3 ├── t.gsub4 ├── t.i.x ├── t.if ├── t.in ├── t.in1 ├── t.in2 ├── t.in3 ├── t.incr ├── t.incr2 ├── t.incr3 ├── t.index ├── t.intest ├── t.intest2 ├── t.j.x ├── t.longstr ├── t.makef ├── t.match ├── t.match1 ├── t.max ├── t.mod ├── t.monotone ├── t.nameval ├── t.next ├── t.not ├── t.null0 ├── t.ofmt ├── t.ofs ├── t.ors ├── t.pat ├── t.pipe ├── t.pp ├── t.pp1 ├── t.pp2 ├── t.printf ├── t.printf2 ├── t.quote ├── t.randk ├── t.re1 ├── t.re1a ├── t.re2 ├── t.re3 ├── t.re4 ├── t.re5 ├── t.re7 ├── t.reFS ├── t.rec ├── t.reg ├── t.roff ├── t.sep ├── t.seqno ├── t.set0 ├── t.set0a ├── t.set0b ├── t.set1 ├── t.set2 ├── t.set3 ├── t.split2 ├── t.split2a ├── t.split3 ├── t.split4 ├── t.split8 ├── t.split9 ├── t.split9a ├── t.stately ├── t.strcmp ├── t.strcmp1 ├── t.strnum ├── t.sub1 ├── t.sub2 ├── t.sub3 ├── t.substr ├── t.substr1 ├── t.time ├── t.vf ├── t.vf1 ├── t.vf2 ├── t.vf3 ├── t.x ├── test.countries ├── test.data ├── tt.01_print ├── tt.02_print_NR_NF ├── tt.02a_print_length ├── tt.03_sum_length ├── tt.03a_sum_field ├── tt.04_printf_fields ├── tt.05_concat_fields ├── tt.06_count_lengths ├── tt.07_even_fields ├── tt.08_even_lengths ├── tt.08z_regex_simple ├── tt.09_regex_starts_with ├── tt.10_regex_ends_with ├── tt.10a_regex_ends_with_var ├── tt.11_substr ├── tt.12_update_fields ├── tt.13_array_ops ├── tt.13a_array_printf ├── tt.14_function_call ├── tt.15_format_lines ├── tt.16_count_words ├── tt.big_complex_program ├── tt.x1_mandelbrot ├── tt.x2_sum_loop └── wildcards ├── a.awk ├── b.awk ├── one.txt └── two.txt /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: benhoyt 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | goawk 3 | orig 4 | fuzz/interp/corpus 5 | fuzz/parser/corpus 6 | fuzz/interp/workdir 7 | fuzz/parser/workdir 8 | fuzz-fuzz.zip 9 | posix_spec.html 10 | goawk_*.zip 11 | goawk_*.tar.gz 12 | .idea 13 | interp/testdata 14 | scripts/csvbench/bin 15 | scripts/csvbench/count.csv 16 | /default.pgo 17 | /goawk-versions 18 | -------------------------------------------------------------------------------- /docs/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/docs/cover.png -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/benhoyt/goawk 2 | 3 | go 1.18 4 | -------------------------------------------------------------------------------- /scripts/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go test ./interp -bench=. -count=5 > benchmarks_new.txt 3 | -------------------------------------------------------------------------------- /scripts/benchstat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ~/go/bin/benchstat -sort=delta -geomean benchmarks_old.txt benchmarks_new.txt 3 | -------------------------------------------------------------------------------- /scripts/csvbench/count.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import sys 3 | 4 | lines, fields = 0, 0 5 | for row in csv.reader(sys.stdin): 6 | lines += 1 7 | fields += len(row) 8 | 9 | print(lines, fields) 10 | -------------------------------------------------------------------------------- /scripts/csvbench/count/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "encoding/csv" 6 | "fmt" 7 | "io" 8 | "log" 9 | "os" 10 | ) 11 | 12 | func main() { 13 | reader := csv.NewReader(bufio.NewReader(os.Stdin)) 14 | lines, fields := 0, 0 15 | for { 16 | row, err := reader.Read() 17 | if err == io.EOF { 18 | break 19 | } 20 | if err != nil { 21 | log.Fatal(err) 22 | } 23 | lines++ 24 | fields += len(row) 25 | } 26 | fmt.Println(lines, fields) 27 | } 28 | -------------------------------------------------------------------------------- /scripts/fuzz_input.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go test ./interp -run=^$ -fuzz=Input -parallel=4 3 | -------------------------------------------------------------------------------- /scripts/fuzz_source.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go test ./interp -run=^$ -fuzz=Source -parallel=4 3 | -------------------------------------------------------------------------------- /testdata/cover/a1.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | print "hello" 3 | callF() 4 | callF() 5 | callF() 6 | exit 0 # this will call END 7 | } 8 | function callF(){ 9 | print "world" 10 | } 11 | END{ print "END" } 12 | -------------------------------------------------------------------------------- /testdata/cover/a1_a2_covermode_count.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | __COVER[1]++ 3 | print "hello" 4 | callF() 5 | callF() 6 | callF() 7 | exit 0 8 | } 9 | 10 | BEGIN { 11 | __COVER[3]++ 12 | if (1) { 13 | __COVER[2]++ 14 | print "hello" 15 | print "world" 16 | } 17 | __COVER[5]++ 18 | print "end" 19 | for (i = 0; i < 7; i++) { 20 | __COVER[4]++ 21 | print i 22 | } 23 | } 24 | 25 | END { 26 | __COVER[6]++ 27 | print "END" 28 | } 29 | 30 | function callF() { 31 | __COVER[7]++ 32 | print "world" 33 | } -------------------------------------------------------------------------------- /testdata/cover/a1_annotation_data.txt: -------------------------------------------------------------------------------- 1 | 1 a1.awk 2:3-6:30 5 2 | 2 a1.awk 11:6-11:18 1 3 | 3 a1.awk 9:3-9:16 1 -------------------------------------------------------------------------------- /testdata/cover/a1_covermode_set.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | __COVER[1] = 1 3 | print "hello" 4 | callF() 5 | callF() 6 | callF() 7 | exit 0 8 | } 9 | 10 | END { 11 | __COVER[2] = 1 12 | print "END" 13 | } 14 | 15 | function callF() { 16 | __COVER[3] = 1 17 | print "world" 18 | } -------------------------------------------------------------------------------- /testdata/cover/a2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | if (1) { 3 | print "hello" 4 | print "world" 5 | } 6 | print "end" 7 | for (i=0; i<7; i++) print i 8 | } -------------------------------------------------------------------------------- /testdata/cover/a2_annotation_data.txt: -------------------------------------------------------------------------------- 1 | 1 a2.awk 3:5-4:18 2 2 | 2 a2.awk 2:3-2:10 1 3 | 3 a2.awk 7:23-7:30 1 4 | 4 a2.awk 6:3-7:23 2 -------------------------------------------------------------------------------- /testdata/cover/a2_covermode_count.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | __COVER[2]++ 3 | if (1) { 4 | __COVER[1]++ 5 | print "hello" 6 | print "world" 7 | } 8 | __COVER[4]++ 9 | print "end" 10 | for (i = 0; i < 7; i++) { 11 | __COVER[3]++ 12 | print i 13 | } 14 | } -------------------------------------------------------------------------------- /testdata/cover/a3.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | if (1) { 3 | for (i=0; i<10; i++) { 4 | print i 5 | while (1) { 6 | do { 7 | for (j in A) { 8 | print j 9 | if (2) { 10 | print 2 11 | { 12 | if (3) print 3 13 | } 14 | } else { 15 | continue 16 | } 17 | } 18 | } while(1) 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /testdata/cover/a3_annotation_data.txt: -------------------------------------------------------------------------------- 1 | 1 a3.awk 12:24-12:31 1 2 | 2 a3.awk 12:17-12:24 1 3 | 3 a3.awk 10:15-13:16 2 4 | 4 a3.awk 15:15-15:23 1 5 | 5 a3.awk 8:13-9:20 2 6 | 6 a3.awk 7:11-7:24 1 7 | 7 a3.awk 6:9-18:19 1 8 | 8 a3.awk 4:7-5:17 2 9 | 9 a3.awk 3:5-3:26 1 10 | 10 a3.awk 2:3-2:10 1 -------------------------------------------------------------------------------- /testdata/cover/test_1file2runs_set.cov: -------------------------------------------------------------------------------- 1 | mode: set 2 | a1.awk:2.3,6.30 5 1 3 | a1.awk:11.6,11.18 1 1 4 | a1.awk:9.3,9.16 1 1 5 | a1.awk:2.3,6.30 5 1 6 | a1.awk:11.6,11.18 1 1 7 | a1.awk:9.3,9.16 1 1 8 | -------------------------------------------------------------------------------- /testdata/cover/test_1file2runs_set_truncated.cov: -------------------------------------------------------------------------------- 1 | mode: set 2 | a1.awk:2.3,6.30 5 1 3 | a1.awk:11.6,11.18 1 1 4 | a1.awk:9.3,9.16 1 1 5 | -------------------------------------------------------------------------------- /testdata/cover/test_2file2runs_count.cov: -------------------------------------------------------------------------------- 1 | mode: count 2 | a2.awk:3.5,4.18 2 1 3 | a2.awk:2.3,2.10 1 1 4 | a2.awk:7.23,7.30 1 7 5 | a2.awk:6.3,7.23 2 1 6 | a1.awk:2.3,6.30 5 1 7 | a1.awk:11.6,11.18 1 1 8 | a1.awk:9.3,9.16 1 3 9 | a2.awk:3.5,4.18 2 1 10 | a2.awk:2.3,2.10 1 1 11 | a2.awk:7.23,7.30 1 7 12 | a2.awk:6.3,7.23 2 1 13 | a1.awk:2.3,6.30 5 1 14 | a1.awk:11.6,11.18 1 1 15 | a1.awk:9.3,9.16 1 3 -------------------------------------------------------------------------------- /testdata/cover/test_2file2runs_count_truncated.cov: -------------------------------------------------------------------------------- 1 | mode: count 2 | a2.awk:3.5,4.18 2 1 3 | a2.awk:2.3,2.10 1 1 4 | a2.awk:7.23,7.30 1 7 5 | a2.awk:6.3,7.23 2 1 6 | a1.awk:2.3,6.30 5 1 7 | a1.awk:11.6,11.18 1 1 8 | a1.awk:9.3,9.16 1 3 -------------------------------------------------------------------------------- /testdata/cover/test_a2a1_count.cov: -------------------------------------------------------------------------------- 1 | mode: count 2 | a2.awk:3.5,4.18 2 1 3 | a2.awk:2.3,2.10 1 1 4 | a2.awk:7.23,7.30 1 7 5 | a2.awk:6.3,7.23 2 1 6 | a1.awk:2.3,6.30 5 1 7 | a1.awk:11.6,11.18 1 1 8 | a1.awk:9.3,9.16 1 3 -------------------------------------------------------------------------------- /testdata/cover/test_a2a1_set.cov: -------------------------------------------------------------------------------- 1 | mode: set 2 | a2.awk:3.5,4.18 2 1 3 | a2.awk:2.3,2.10 1 1 4 | a2.awk:7.23,7.30 1 1 5 | a2.awk:6.3,7.23 2 1 6 | a1.awk:2.3,6.30 5 1 7 | a1.awk:11.6,11.18 1 1 8 | a1.awk:9.3,9.16 1 1 -------------------------------------------------------------------------------- /testdata/cover/test_count.cov: -------------------------------------------------------------------------------- 1 | mode: count 2 | a1.awk:2.3,6.30 5 1 3 | a1.awk:11.6,11.18 1 1 4 | a1.awk:9.3,9.16 1 3 5 | -------------------------------------------------------------------------------- /testdata/cover/test_set.cov: -------------------------------------------------------------------------------- 1 | mode: set 2 | a1.awk:2.3,6.30 5 1 3 | a1.awk:11.6,11.18 1 1 4 | a1.awk:9.3,9.16 1 1 5 | -------------------------------------------------------------------------------- /testdata/csv/1.csv: -------------------------------------------------------------------------------- 1 | name,age 2 | Bob,42 3 | Jill,37 4 | -------------------------------------------------------------------------------- /testdata/csv/2.csv: -------------------------------------------------------------------------------- 1 | age,email,name 2 | 25,sarah@example.com,Sarah 3 | -------------------------------------------------------------------------------- /testdata/csv/address5.csv: -------------------------------------------------------------------------------- 1 | name,address_1,address_2,address_3,address_4,address_5 2 | Bob Smith,123 Way St,Apt 2B,Township,Cityville,United Plates 3 | -------------------------------------------------------------------------------- /testdata/csv/fields.csv: -------------------------------------------------------------------------------- 1 | id,name,email 2 | 1,Bob,b@bob.com 3 | -------------------------------------------------------------------------------- /testdata/filename/10: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /testdata/filename/10x: -------------------------------------------------------------------------------- 1 | bar 2 | -------------------------------------------------------------------------------- /testdata/g.1: -------------------------------------------------------------------------------- 1 | ONE 2 | -------------------------------------------------------------------------------- /testdata/g.2: -------------------------------------------------------------------------------- 1 | TWO 2 | -------------------------------------------------------------------------------- /testdata/g.3: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | printf "A=%d, B=%d\n", A, B 3 | for (i = 1; i < ARGC; i++) { 4 | printf "\tARGV[%d] = %s\n", i, ARGV[i] 5 | } 6 | } 7 | 8 | END { 9 | printf "A=%d, B=%d\n", A, B 10 | } 11 | -------------------------------------------------------------------------------- /testdata/g.4: -------------------------------------------------------------------------------- 1 | FOUR a 2 | FOUR b 3 | -------------------------------------------------------------------------------- /testdata/g.5: -------------------------------------------------------------------------------- 1 | one 2 | two 2 3 | 3 4 | Four 5 | -------------------------------------------------------------------------------- /testdata/g.6: -------------------------------------------------------------------------------- 1 | Uno 2 | Duo 3 | Tri 4 | -------------------------------------------------------------------------------- /testdata/gawk/addcomma.awk: -------------------------------------------------------------------------------- 1 | # addcomma - put commas in numbers 2 | # input: a number per line 3 | # output: the input number followed by 4 | # the number with commas and two decimal places 5 | 6 | { printf("%-12s %20s\n", $0, addcomma($0)) } 7 | 8 | function addcomma(x, num) { 9 | if (x < 0) 10 | return "-" addcomma(-x) 11 | num = sprintf("%.2f", x) # num is dddddd.dd 12 | while (num ~ /[0-9][0-9][0-9][0-9]/) 13 | sub(/[0-9][0-9][0-9][,.]/, ",&", num) 14 | return num 15 | } 16 | -------------------------------------------------------------------------------- /testdata/gawk/addcomma.in: -------------------------------------------------------------------------------- 1 | 0 2 | -1 3 | -12.34 4 | 12345 5 | -1234567.89 6 | -123. 7 | -123456 8 | -------------------------------------------------------------------------------- /testdata/gawk/addcomma.ok: -------------------------------------------------------------------------------- 1 | 0 0.00 2 | -1 -1.00 3 | -12.34 -12.34 4 | 12345 12,345.00 5 | -1234567.89 -1,234,567.89 6 | -123. -123.00 7 | -123456 -123,456.00 8 | -------------------------------------------------------------------------------- /testdata/gawk/anchgsub.awk: -------------------------------------------------------------------------------- 1 | { gsub(/^[ ]*/, "", $0) ; print } 2 | -------------------------------------------------------------------------------- /testdata/gawk/anchgsub.in: -------------------------------------------------------------------------------- 1 | This is a test, this is only a test. 2 | -------------------------------------------------------------------------------- /testdata/gawk/anchgsub.ok: -------------------------------------------------------------------------------- 1 | This is a test, this is only a test. 2 | -------------------------------------------------------------------------------- /testdata/gawk/anchor.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "" } 2 | 3 | { 4 | if (/^A/) 5 | print "ok" 6 | else 7 | print "not ok" 8 | 9 | if (/B$/) 10 | print "not ok" 11 | else 12 | print "ok" 13 | 14 | if (/^C/) 15 | print "not ok" 16 | else 17 | print "ok" 18 | 19 | if (/D$/) 20 | print "not ok" 21 | else 22 | print "ok" 23 | 24 | if (/^E/) 25 | print "not ok" 26 | else 27 | print "ok" 28 | 29 | if (/F$/) 30 | print "ok" 31 | else 32 | print "not ok" 33 | } 34 | -------------------------------------------------------------------------------- /testdata/gawk/anchor.in: -------------------------------------------------------------------------------- 1 | A line1 B 2 | C line2 D 3 | E line3 F 4 | -------------------------------------------------------------------------------- /testdata/gawk/anchor.ok: -------------------------------------------------------------------------------- 1 | ok 2 | ok 3 | ok 4 | ok 5 | ok 6 | ok 7 | -------------------------------------------------------------------------------- /testdata/gawk/argarray.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | argn = " argument" (ARGC > 1 ? "s" : "") 3 | are = ARGC > 1 ? "are" : "is" 4 | print "here we have " ARGC argn 5 | print "which " are 6 | for (x = 0; x < ARGC; x++) 7 | print "\t", ARGV[x] 8 | print "Environment variable TEST=" ENVIRON["TEST"] 9 | print "and the current input file is called \"" FILENAME "\"" 10 | } 11 | 12 | FNR == 1 { 13 | print "in main loop, this input file is known as \"" FILENAME "\"" 14 | } 15 | -------------------------------------------------------------------------------- /testdata/gawk/argarray.in: -------------------------------------------------------------------------------- 1 | this is a simple test file 2 | -------------------------------------------------------------------------------- /testdata/gawk/argarray.ok: -------------------------------------------------------------------------------- 1 | here we have 1 argument 2 | which is 3 | 4 | Environment variable TEST= 5 | and the current input file is called "" 6 | in main loop, this input file is known as "-" 7 | -------------------------------------------------------------------------------- /testdata/gawk/arrayind3.ok: -------------------------------------------------------------------------------- 1 | 2 | 1 3 | -------------------------------------------------------------------------------- /testdata/gawk/arrayparm.awk: -------------------------------------------------------------------------------- 1 | # 2 | # Test program from: 3 | # 4 | # Date: Tue, 21 Feb 95 16:09:29 EST 5 | # From: emory!blackhawk.com!aaron (Aaron Sosnick) 6 | # 7 | BEGIN { 8 | foo[1]=1; 9 | foo[2]=2; 10 | bug1(foo); 11 | } 12 | function bug1(i) { 13 | for (i in foo) { 14 | bug2(i); 15 | delete foo[i]; 16 | print i,1,bot[1]; 17 | } 18 | } 19 | function bug2(arg) { 20 | bot[arg]=arg; 21 | } 22 | -------------------------------------------------------------------------------- /testdata/gawk/arrayparm.ok: -------------------------------------------------------------------------------- 1 | parse error at 10:10: can't pass array "foo" as scalar param -------------------------------------------------------------------------------- /testdata/gawk/arrayprm2.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/arrayprm2.ok -------------------------------------------------------------------------------- /testdata/gawk/arrayprm3.ok: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/gawk/arrayref.awk: -------------------------------------------------------------------------------- 1 | BEGIN { # foo[10] = 0 # put this line in and it will work 2 | test(foo); print foo[1] 3 | test2(foo2); print foo2[1] 4 | } 5 | 6 | function test(foo) 7 | { 8 | test2(foo) 9 | } 10 | function test2(bar) 11 | { 12 | bar[1] = 1 13 | } 14 | -------------------------------------------------------------------------------- /testdata/gawk/arrayref.ok: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | -------------------------------------------------------------------------------- /testdata/gawk/arrymem1.ok: -------------------------------------------------------------------------------- 1 | test 2 | b[""] = "b" 3 | -------------------------------------------------------------------------------- /testdata/gawk/arryref2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | foo(a) 3 | 4 | for (i in a) 5 | print i, a[i] 6 | } 7 | 8 | function foo(b) 9 | { 10 | bar(b) 11 | b[2] = "local" 12 | } 13 | 14 | function bar(c) 15 | { 16 | a[3] = "global" 17 | c[1] = "local2" 18 | } 19 | -------------------------------------------------------------------------------- /testdata/gawk/arryref2.ok: -------------------------------------------------------------------------------- 1 | 1 local2 2 | 2 local 3 | 3 global 4 | -------------------------------------------------------------------------------- /testdata/gawk/arryref3.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | foo(a) 3 | 4 | for (i in a) 5 | print i, a[i] 6 | } 7 | 8 | function foo(b) 9 | { 10 | a[1] = "global" 11 | b[2] = "local" 12 | bar(b) 13 | } 14 | 15 | function bar(c) 16 | { 17 | c = 12 18 | } 19 | -------------------------------------------------------------------------------- /testdata/gawk/arryref3.ok: -------------------------------------------------------------------------------- 1 | parse error at 12:6: can't pass array "b" as scalar param -------------------------------------------------------------------------------- /testdata/gawk/arryref4.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | foo(a) 3 | 4 | print a 5 | } 6 | 7 | function foo(b) 8 | { 9 | a = "global" 10 | b[2] = "local" 11 | # bar(b) 12 | } 13 | 14 | function bar(c) 15 | { 16 | c = 12 17 | } 18 | -------------------------------------------------------------------------------- /testdata/gawk/arryref4.ok: -------------------------------------------------------------------------------- 1 | parse error at 2:6: can't pass scalar "a" as array param -------------------------------------------------------------------------------- /testdata/gawk/arryref5.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | foo(a) 3 | 4 | print a 5 | } 6 | 7 | function foo(b) 8 | { 9 | b[2] = "local" 10 | a = "global" 11 | # bar(b) 12 | } 13 | 14 | function bar(c) 15 | { 16 | c = 12 17 | } 18 | -------------------------------------------------------------------------------- /testdata/gawk/arryref5.ok: -------------------------------------------------------------------------------- 1 | parse error at 2:6: can't pass scalar "a" as array param -------------------------------------------------------------------------------- /testdata/gawk/arynasty.ok: -------------------------------------------------------------------------------- 1 | test[12.153] = hi 2 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm1.awk: -------------------------------------------------------------------------------- 1 | function f(a) { 2 | if (3 in a) 3 | print 7 4 | a = 5 5 | } 6 | 7 | BEGIN { 8 | f(arr) 9 | } 10 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm1.ok: -------------------------------------------------------------------------------- 1 | parse error at 4:2: can't use array "a" as scalar -------------------------------------------------------------------------------- /testdata/gawk/aryprm3.awk: -------------------------------------------------------------------------------- 1 | function f(a, i) { 2 | for (i in a) 3 | delete a[i] 4 | if (a == 0) 5 | print 7 6 | } 7 | 8 | BEGIN { 9 | f(arr) 10 | } 11 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm3.ok: -------------------------------------------------------------------------------- 1 | parse error at 4:6: can't use array "a" as scalar -------------------------------------------------------------------------------- /testdata/gawk/aryprm4.awk: -------------------------------------------------------------------------------- 1 | function f(x){ 2 | x = 1 3 | } 4 | BEGIN { 5 | f(a) 6 | a[1] 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm4.ok: -------------------------------------------------------------------------------- 1 | parse error at 6:2: can't use scalar "a" as array -------------------------------------------------------------------------------- /testdata/gawk/aryprm5.awk: -------------------------------------------------------------------------------- 1 | function f(x){ 2 | x[1] = x 3 | } 4 | BEGIN { 5 | f(a) 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm5.ok: -------------------------------------------------------------------------------- 1 | parse error at 2:9: can't use array "x" as scalar -------------------------------------------------------------------------------- /testdata/gawk/aryprm6.awk: -------------------------------------------------------------------------------- 1 | function f(x){ 2 | a 3 | x[1] = 3 4 | } 5 | BEGIN { 6 | f(a) 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm6.ok: -------------------------------------------------------------------------------- 1 | parse error at 6:4: can't pass scalar "a" as array param -------------------------------------------------------------------------------- /testdata/gawk/aryprm7.awk: -------------------------------------------------------------------------------- 1 | function f(x, y){ 2 | y[1] = x 3 | } 4 | BEGIN { 5 | f(a, a) 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm7.ok: -------------------------------------------------------------------------------- 1 | parse error at 5:7: can't pass scalar "a" as array param -------------------------------------------------------------------------------- /testdata/gawk/aryprm8.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | f(0, a) # nothing 3 | f(1, a) 4 | } 5 | function f(i, a) { 6 | if (i == 0) return 7 | g(a, a) 8 | pr(a) 9 | } 10 | function g(x, y) { 11 | h(y, x, y) 12 | } 13 | function h(b, c, d) { 14 | b[1] = 1 15 | c[1] = 2 # rewrite 16 | print b[1], d[1] 17 | c[2] = 1 18 | b[2] = 2 # should rewrite 19 | } 20 | function pr(x) { 21 | print x[1], x[2] 22 | } 23 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm8.ok: -------------------------------------------------------------------------------- 1 | 2 2 2 | 2 2 3 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm9.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/gawk -f 2 | BEGIN { 3 | 4 | for (i = 0; i < 100; i++) 5 | func_exec() 6 | } 7 | 8 | function func_exec(opaque) 9 | { 10 | func_a(1, opaque) #set additional argument, not expected by fname 11 | } 12 | 13 | function func_a(a, b, loc1, loc2) 14 | { 15 | b = 0 #unref Nnull_string 16 | } 17 | -------------------------------------------------------------------------------- /testdata/gawk/aryprm9.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/aryprm9.ok -------------------------------------------------------------------------------- /testdata/gawk/arysubnm.awk: -------------------------------------------------------------------------------- 1 | BEGIN { n = 11 ; foo[n] = n; print (2 <= n) } 2 | -------------------------------------------------------------------------------- /testdata/gawk/arysubnm.ok: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/gawk/aryunasgn.ok: -------------------------------------------------------------------------------- 1 | 0 null 2 | 0 1 3 | null 4 | 5 | 0 null 6 | 0 1 7 | null also 8 | 9 | -------------------------------------------------------------------------------- /testdata/gawk/asgext.awk: -------------------------------------------------------------------------------- 1 | { print $3; $4 = "a"; print } 2 | -------------------------------------------------------------------------------- /testdata/gawk/asgext.in: -------------------------------------------------------------------------------- 1 | 1 2 3 2 | 1 3 | 1 2 3 4 4 | -------------------------------------------------------------------------------- /testdata/gawk/asgext.ok: -------------------------------------------------------------------------------- 1 | 3 2 | 1 2 3 a 3 | 4 | 1 a 5 | 3 6 | 1 2 3 a 7 | -------------------------------------------------------------------------------- /testdata/gawk/assignnumfield.awk: -------------------------------------------------------------------------------- 1 | {$0 = ++i} 1 2 | -------------------------------------------------------------------------------- /testdata/gawk/assignnumfield.in: -------------------------------------------------------------------------------- 1 | a b c 2 | a b c 3 | a b c 4 | a b c 5 | a b c 6 | -------------------------------------------------------------------------------- /testdata/gawk/assignnumfield.ok: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | -------------------------------------------------------------------------------- /testdata/gawk/back89.awk: -------------------------------------------------------------------------------- 1 | /a\8b/ 2 | -------------------------------------------------------------------------------- /testdata/gawk/back89.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:1: error parsing regexp: invalid escape sequence: `\8` -------------------------------------------------------------------------------- /testdata/gawk/backgsub.awk: -------------------------------------------------------------------------------- 1 | { 2 | gsub( "\\\\", "\\\\") 3 | print 4 | } 5 | -------------------------------------------------------------------------------- /testdata/gawk/backgsub.in: -------------------------------------------------------------------------------- 1 | \x\y\z 2 | -------------------------------------------------------------------------------- /testdata/gawk/backgsub.ok: -------------------------------------------------------------------------------- 1 | \x\y\z 2 | -------------------------------------------------------------------------------- /testdata/gawk/badassign1.awk: -------------------------------------------------------------------------------- 1 | BEGIN { $i++ = 3 ; print i } 2 | -------------------------------------------------------------------------------- /testdata/gawk/badassign1.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:9: expected lvalue before = -------------------------------------------------------------------------------- /testdata/gawk/badbuild.awk: -------------------------------------------------------------------------------- 1 | $1 == $2 == $3 { 2 | print "Gawk was built incorrectly." 3 | print "Use bison, not byacc or something else!" 4 | print "(Really, why aren't you using the awkgram.c in the distribution?)" 5 | exit 42 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/badbuild.in: -------------------------------------------------------------------------------- 1 | a a 1 2 | -------------------------------------------------------------------------------- /testdata/gawk/badbuild.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:10: expected , instead of == -------------------------------------------------------------------------------- /testdata/gawk/callparam.awk: -------------------------------------------------------------------------------- 1 | BEGIN { f() } 2 | 3 | function f( a, b) 4 | { 5 | a = b() 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/callparam.ok: -------------------------------------------------------------------------------- 1 | parse error at 5:6: can't call local variable "b" as function -------------------------------------------------------------------------------- /testdata/gawk/childin.awk: -------------------------------------------------------------------------------- 1 | BEGIN { "cat" | getline; print; close("cat") } 2 | -------------------------------------------------------------------------------- /testdata/gawk/childin.in: -------------------------------------------------------------------------------- 1 | hi 2 | -------------------------------------------------------------------------------- /testdata/gawk/childin.ok: -------------------------------------------------------------------------------- 1 | hi 2 | -------------------------------------------------------------------------------- /testdata/gawk/clobber.ok: -------------------------------------------------------------------------------- 1 | 000801 -------------------------------------------------------------------------------- /testdata/gawk/closebad.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | f = "/no/such/file/1" 3 | print (getline junk < f) 4 | print close(f) 5 | f = "/no/such/file/2" 6 | print close(f) 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/closebad.ok: -------------------------------------------------------------------------------- 1 | -1 2 | -1 3 | -1 4 | -------------------------------------------------------------------------------- /testdata/gawk/compare.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | if ("0") print "zero" 3 | if ("") print "null" 4 | if (0) print 0 5 | } 6 | { 7 | if ($0) print $0 8 | if ($1) print $1 9 | } 10 | -------------------------------------------------------------------------------- /testdata/gawk/compare.in: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 1 4 | 5 | -------------------------------------------------------------------------------- /testdata/gawk/compare.ok: -------------------------------------------------------------------------------- 1 | zero 2 | 1 3 | 1 4 | 0 1 5 | -------------------------------------------------------------------------------- /testdata/gawk/compare2.ok: -------------------------------------------------------------------------------- 1 | OK: zero strings compare equal to number zero 2 | -------------------------------------------------------------------------------- /testdata/gawk/concat1.in: -------------------------------------------------------------------------------- 1 | A 2 | B 3 | C 4 | D 5 | -------------------------------------------------------------------------------- /testdata/gawk/concat1.ok: -------------------------------------------------------------------------------- 1 | Input = A ; 2 | Input = B ; 3 | Input = C ; 4 | Input = D ; 5 | -------------------------------------------------------------------------------- /testdata/gawk/concat2.awk: -------------------------------------------------------------------------------- 1 | function f(s, x) { 2 | x = 1 3 | s = 3 4 | s = s x 5 | print s 6 | } 7 | 8 | BEGIN { for (i = 1; i <=12; i++) f() } 9 | -------------------------------------------------------------------------------- /testdata/gawk/concat2.ok: -------------------------------------------------------------------------------- 1 | 31 2 | 31 3 | 31 4 | 31 5 | 31 6 | 31 7 | 31 8 | 31 9 | 31 10 | 31 11 | 31 12 | 31 13 | -------------------------------------------------------------------------------- /testdata/gawk/concat3.awk: -------------------------------------------------------------------------------- 1 | BEGIN { a; a = a (b "c"); print a; print b } 2 | -------------------------------------------------------------------------------- /testdata/gawk/concat3.ok: -------------------------------------------------------------------------------- 1 | c 2 | 3 | -------------------------------------------------------------------------------- /testdata/gawk/concat4.awk: -------------------------------------------------------------------------------- 1 | { 2 | a = $0 3 | print a 4 | print index(a,"b") 5 | getline 6 | a = a $0 7 | print a 8 | print index(a,"b") 9 | } 10 | -------------------------------------------------------------------------------- /testdata/gawk/concat4.in: -------------------------------------------------------------------------------- 1 | foo 2 | bar 3 | -------------------------------------------------------------------------------- /testdata/gawk/concat4.ok: -------------------------------------------------------------------------------- 1 | foo 2 | 0 3 | foobar 4 | 4 5 | -------------------------------------------------------------------------------- /testdata/gawk/concat5.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | OFMT = "%.8g" 3 | x = 1 4 | x += .1 5 | x = (x "a") 6 | print x 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/concat5.ok: -------------------------------------------------------------------------------- 1 | 1.1a 2 | -------------------------------------------------------------------------------- /testdata/gawk/convfmt.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | CONVFMT = "%2.2f" 3 | a = 123.456 4 | b = a "" # give `a' string value also 5 | printf "a = %s\n", a 6 | CONVFMT = "%.6g" 7 | printf "a = %s\n", a 8 | a += 0 # make `a' numeric only again 9 | printf "a = %s\n", a # use `a' as string 10 | } 11 | -------------------------------------------------------------------------------- /testdata/gawk/convfmt.ok: -------------------------------------------------------------------------------- 1 | a = 123.46 2 | a = 123.456 3 | a = 123.456 4 | -------------------------------------------------------------------------------- /testdata/gawk/datanonl.awk: -------------------------------------------------------------------------------- 1 | # example program from alex@bofh.torun.pl 2 | BEGIN { IGNORECASE=1 } 3 | /\w+@([[:alnum:]]+\.)+[[:alnum:]]+[[:blank:]]+/ {print $0} 4 | -------------------------------------------------------------------------------- /testdata/gawk/datanonl.in: -------------------------------------------------------------------------------- 1 | bleble@foo1.bh.pl deny -------------------------------------------------------------------------------- /testdata/gawk/datanonl.ok: -------------------------------------------------------------------------------- 1 | bleble@foo1.bh.pl deny 2 | -------------------------------------------------------------------------------- /testdata/gawk/defref.awk: -------------------------------------------------------------------------------- 1 | BEGIN { foo() } 2 | -------------------------------------------------------------------------------- /testdata/gawk/defref.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:9: undefined function "foo" -------------------------------------------------------------------------------- /testdata/gawk/delargv.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | ARGV[1] = "/dev/null" 3 | ARGV[2] = "/dev/null" 4 | ARGV[3] = "/dev/null" 5 | ARGC = 4 6 | delete ARGV[2] 7 | } 8 | 9 | END { 10 | for (i in ARGV) 11 | printf("length of ARGV[%d] is %d\n", i, length(ARGV[i])) 12 | } 13 | -------------------------------------------------------------------------------- /testdata/gawk/delargv.ok: -------------------------------------------------------------------------------- 1 | length of ARGV[0] is 0 2 | length of ARGV[1] is 9 3 | length of ARGV[3] is 9 4 | -------------------------------------------------------------------------------- /testdata/gawk/delarpm2.ok: -------------------------------------------------------------------------------- 1 | 1 one 2 | 2 two 3 | -------------------------------------------------------------------------------- /testdata/gawk/delfunc.awk: -------------------------------------------------------------------------------- 1 | # from Stepan Kasal, 9 July 2003 2 | function f() 3 | { 4 | delete f 5 | } 6 | 7 | BEGIN { f() } 8 | -------------------------------------------------------------------------------- /testdata/gawk/delfunc.ok: -------------------------------------------------------------------------------- 1 | parse error at 4:9: global var "f" can't also be a function -------------------------------------------------------------------------------- /testdata/gawk/dfastress.awk: -------------------------------------------------------------------------------- 1 | BEGIN { print "a" ~ /(^| )*(a|b)*(c|d)( |$)/ } 2 | -------------------------------------------------------------------------------- /testdata/gawk/dfastress.ok: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testdata/gawk/dynlj.awk: -------------------------------------------------------------------------------- 1 | BEGIN { printf "%*sworld\n", -20, "hello" } 2 | -------------------------------------------------------------------------------- /testdata/gawk/dynlj.ok: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /testdata/gawk/eofsplit.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/eofsplit.ok -------------------------------------------------------------------------------- /testdata/gawk/exit2.awk: -------------------------------------------------------------------------------- 1 | function _fn0() { exit } 2 | BEGIN { ARRAY[_fn0()] } 3 | -------------------------------------------------------------------------------- /testdata/gawk/exit2.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/exit2.ok -------------------------------------------------------------------------------- /testdata/gawk/exitval2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { print "foo" | "read x ; echo $x ; exit 12" } 2 | # this should still exit 0, as pointed out by kenny mccormack in 3 | # comp.lang.awk on 2 feb 2005 4 | -------------------------------------------------------------------------------- /testdata/gawk/exitval2.ok: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /testdata/gawk/fcall_exit.ok: -------------------------------------------------------------------------------- 1 | true(1, crash()) => do not crash properly. 2 | -------------------------------------------------------------------------------- /testdata/gawk/fcall_exit2.awk: -------------------------------------------------------------------------------- 1 | #!/bin/awk -f 2 | 3 | function crash () { 4 | exit 1 5 | } 6 | 7 | function true (a,b,c) { 8 | return 1 9 | } 10 | 11 | BEGIN { 12 | if (ARGV[2] == 1) { 13 | print " true(1, crash()) => crash properly." 14 | true(1, crash()) 15 | # ADR: Added: 16 | delete ARGV[2] 17 | } 18 | } 19 | 20 | { 21 | print " true(1, crash()) => do not crash properly." 22 | true(1, crash()) 23 | } 24 | 25 | # FdF 26 | -------------------------------------------------------------------------------- /testdata/gawk/fcall_exit2.in: -------------------------------------------------------------------------------- 1 | dummy input line 2 | -------------------------------------------------------------------------------- /testdata/gawk/fcall_exit2.ok: -------------------------------------------------------------------------------- 1 | true(1, crash()) => do not crash properly. 2 | -------------------------------------------------------------------------------- /testdata/gawk/fldchg.awk: -------------------------------------------------------------------------------- 1 | { 2 | # print "0:", $0 3 | gsub("aa", "+") 4 | print "1:", $0 5 | $3 = "<" $3 ">" 6 | print "2:", $0 7 | print "2a:" "%" $1 "%" $2 "%" $3 "%" $4 "%" $5 8 | } 9 | -------------------------------------------------------------------------------- /testdata/gawk/fldchg.in: -------------------------------------------------------------------------------- 1 | aa aab c d e f 2 | -------------------------------------------------------------------------------- /testdata/gawk/fldchg.ok: -------------------------------------------------------------------------------- 1 | 1: + +b c d e f 2 | 2: + +b d e f 3 | 2a:%+%+b%%d%e 4 | -------------------------------------------------------------------------------- /testdata/gawk/fldchgnf.awk: -------------------------------------------------------------------------------- 1 | { OFS = ":"; $2 = ""; print $0; print NF } 2 | -------------------------------------------------------------------------------- /testdata/gawk/fldchgnf.in: -------------------------------------------------------------------------------- 1 | a b c d 2 | -------------------------------------------------------------------------------- /testdata/gawk/fldchgnf.ok: -------------------------------------------------------------------------------- 1 | a::c:d 2 | 4 3 | -------------------------------------------------------------------------------- /testdata/gawk/fldterm.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | # choose a field separator that is numeric, so we can test whether 3 | # force_number properly handles unterminated numeric field strings 4 | FS = "3" 5 | } 6 | 7 | { 8 | print $1+0 9 | print $1 10 | } 11 | -------------------------------------------------------------------------------- /testdata/gawk/fldterm.in: -------------------------------------------------------------------------------- 1 | 5.53apple 2 | -------------------------------------------------------------------------------- /testdata/gawk/fldterm.ok: -------------------------------------------------------------------------------- 1 | 5.5 2 | 5.5 3 | -------------------------------------------------------------------------------- /testdata/gawk/fnamedat.awk: -------------------------------------------------------------------------------- 1 | function foo() { print foo } {foo()} 2 | -------------------------------------------------------------------------------- /testdata/gawk/fnamedat.in: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /testdata/gawk/fnamedat.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:24: global var "foo" can't also be a function -------------------------------------------------------------------------------- /testdata/gawk/fnarray.awk: -------------------------------------------------------------------------------- 1 | function foo(N) { 2 | return 0 3 | } 4 | BEGIN { 5 | Num = foo[c] 6 | } 7 | 8 | -------------------------------------------------------------------------------- /testdata/gawk/fnarray.ok: -------------------------------------------------------------------------------- 1 | parse error at 5:9: global var "foo" can't also be a function -------------------------------------------------------------------------------- /testdata/gawk/fnarray2.awk: -------------------------------------------------------------------------------- 1 | function pile(c, r) 2 | { 3 | r = ++pile[c] 4 | } 5 | { pile($1) } 6 | -------------------------------------------------------------------------------- /testdata/gawk/fnarray2.in: -------------------------------------------------------------------------------- 1 | x 2 | -------------------------------------------------------------------------------- /testdata/gawk/fnarray2.ok: -------------------------------------------------------------------------------- 1 | parse error at 3:8: global var "pile" can't also be a function -------------------------------------------------------------------------------- /testdata/gawk/fnaryscl.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | foo[1] = 4 3 | f1(foo) 4 | } 5 | 6 | function f1(a) { f2(a) } 7 | 8 | function f2(b) { f3(b) } 9 | 10 | function f3(c) { c = 6 } 11 | -------------------------------------------------------------------------------- /testdata/gawk/fnaryscl.ok: -------------------------------------------------------------------------------- 1 | parse error at 3:5: can't pass array "foo" as scalar param -------------------------------------------------------------------------------- /testdata/gawk/fnasgnm.in: -------------------------------------------------------------------------------- 1 | junk 2 | -------------------------------------------------------------------------------- /testdata/gawk/fnasgnm.ok: -------------------------------------------------------------------------------- 1 | parse error at 14:20: global var "ShowMe" can't also be a function -------------------------------------------------------------------------------- /testdata/gawk/fnmisc.awk: -------------------------------------------------------------------------------- 1 | # Tue Feb 4 12:20:10 IST 2003 2 | 3 | # Misc functions tests, in case we start mucking around in the grammar again. 4 | 5 | # Empty body shouldn't hurt anything: 6 | function f() {} 7 | BEGIN { f() } 8 | 9 | # Using a built-in function name should manage the symbol table 10 | # correctly: 11 | function split(x) { return x } 12 | 13 | function x(a) { return a } 14 | -------------------------------------------------------------------------------- /testdata/gawk/fnmisc.ok: -------------------------------------------------------------------------------- 1 | parse error at 11:10: expected name instead of split -------------------------------------------------------------------------------- /testdata/gawk/forref.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | names[1] = "s" 3 | names[2] = "m" 4 | for (i in names) { 5 | x[names[i]] = i 6 | print i, names[i], x[names[i]] 7 | } 8 | print x["s"] 9 | # adump(x) 10 | # adump(names) 11 | } 12 | -------------------------------------------------------------------------------- /testdata/gawk/forref.ok: -------------------------------------------------------------------------------- 1 | 1 s 1 2 | 2 m 2 3 | 1 4 | -------------------------------------------------------------------------------- /testdata/gawk/forsimp.awk: -------------------------------------------------------------------------------- 1 | BEGIN { for (print 9; 0;); } 2 | -------------------------------------------------------------------------------- /testdata/gawk/forsimp.ok: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /testdata/gawk/fsbs.awk: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\\" } 2 | { print $1, $2} 3 | -------------------------------------------------------------------------------- /testdata/gawk/fsbs.in: -------------------------------------------------------------------------------- 1 | 1\2 2 | -------------------------------------------------------------------------------- /testdata/gawk/fsbs.ok: -------------------------------------------------------------------------------- 1 | 1 2 2 | -------------------------------------------------------------------------------- /testdata/gawk/fsnul1.awk: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\0" ; RS = "" } 2 | { print $2 } 3 | -------------------------------------------------------------------------------- /testdata/gawk/fsnul1.in: -------------------------------------------------------------------------------- 1 | hiho 2 | -------------------------------------------------------------------------------- /testdata/gawk/fsnul1.ok: -------------------------------------------------------------------------------- 1 | ho 2 | -------------------------------------------------------------------------------- /testdata/gawk/fsrs.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | RS=""; FS="\n"; 3 | ORS=""; OFS="\n"; 4 | } 5 | { 6 | split ($2,f," ") 7 | print $0; 8 | } 9 | -------------------------------------------------------------------------------- /testdata/gawk/fsrs.in: -------------------------------------------------------------------------------- 1 | a b 2 | c d 3 | e f 4 | 5 | 1 2 6 | 3 4 7 | 5 6 8 | -------------------------------------------------------------------------------- /testdata/gawk/fsrs.ok: -------------------------------------------------------------------------------- 1 | a b 2 | c d 3 | e f1 2 4 | 3 4 5 | 5 6 -------------------------------------------------------------------------------- /testdata/gawk/fsspcoln.in: -------------------------------------------------------------------------------- 1 | a:b:c 2 | -------------------------------------------------------------------------------- /testdata/gawk/fsspcoln.ok: -------------------------------------------------------------------------------- 1 | b 2 | -------------------------------------------------------------------------------- /testdata/gawk/fstabplus.awk: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\t+" } 2 | { print $1, $2 } 3 | -------------------------------------------------------------------------------- /testdata/gawk/fstabplus.in: -------------------------------------------------------------------------------- 1 | 1 2 2 | -------------------------------------------------------------------------------- /testdata/gawk/fstabplus.ok: -------------------------------------------------------------------------------- 1 | 1 2 2 | -------------------------------------------------------------------------------- /testdata/gawk/funlen.in: -------------------------------------------------------------------------------- 1 | CD NAME 2 | AT Austria 3 | BG Bulgaria 4 | CH Switzerland 5 | DE Germany 6 | EE Estonia 7 | FR France 8 | GR Greece 9 | -------------------------------------------------------------------------------- /testdata/gawk/funlen.ok: -------------------------------------------------------------------------------- 1 | array: 7 2 | array_A: 7 3 | -------------------------------------------------------------------------------- /testdata/gawk/funsemnl.awk: -------------------------------------------------------------------------------- 1 | # make sure that ; + \n at end after function works 2 | function foo() { print "foo" } ; 3 | BEGIN { foo() } 4 | -------------------------------------------------------------------------------- /testdata/gawk/funsemnl.ok: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /testdata/gawk/funsmnam.awk: -------------------------------------------------------------------------------- 1 | function foo( \ 2 | foo) 3 | { 4 | print foo 5 | } 6 | { foo() } 7 | -------------------------------------------------------------------------------- /testdata/gawk/funsmnam.ok: -------------------------------------------------------------------------------- 1 | parse error at 2:2: can't use function name as parameter name -------------------------------------------------------------------------------- /testdata/gawk/funstack.ok: -------------------------------------------------------------------------------- 1 | parse error at 381:8: error parsing regexp: invalid escape sequence: `\e` -------------------------------------------------------------------------------- /testdata/gawk/getline.in: -------------------------------------------------------------------------------- 1 | A 2 | B 3 | C 4 | -------------------------------------------------------------------------------- /testdata/gawk/getline.ok: -------------------------------------------------------------------------------- 1 | 1s A 2 | 2 B 3 | -1 C 4 | 1s A 5 | 2 B 6 | -1 C 7 | 1 D 8 | date 9 | -------------------------------------------------------------------------------- /testdata/gawk/getline2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { while( getline > 0) { print } } 2 | -------------------------------------------------------------------------------- /testdata/gawk/getline2.in: -------------------------------------------------------------------------------- 1 | BEGIN { while( getline > 0) { print } } 2 | BEGIN { while( getline > 0) { print } } 3 | -------------------------------------------------------------------------------- /testdata/gawk/getline2.ok: -------------------------------------------------------------------------------- 1 | BEGIN { while( getline > 0) { print } } 2 | BEGIN { while( getline > 0) { print } } 3 | -------------------------------------------------------------------------------- /testdata/gawk/getline3.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | cmd = "echo 3" 3 | y = 7 4 | cmd | getline x y 5 | close(cmd) 6 | print (cmd | getline x y) 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/getline3.ok: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /testdata/gawk/getline4.awk: -------------------------------------------------------------------------------- 1 | END { getline $2; print} 2 | -------------------------------------------------------------------------------- /testdata/gawk/getline4.in: -------------------------------------------------------------------------------- 1 | aaa bbb 2 | -------------------------------------------------------------------------------- /testdata/gawk/getline4.ok: -------------------------------------------------------------------------------- 1 | aaa bbb 2 | -------------------------------------------------------------------------------- /testdata/gawk/getline5.ok: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testdata/gawk/getnr2tb.in: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line 5 6 | line 6 7 | -------------------------------------------------------------------------------- /testdata/gawk/getnr2tb.ok: -------------------------------------------------------------------------------- 1 | 1 10 2 | 2 5 3 | 3 3.33333 4 | 4 2.5 5 | 5 2 6 | 6 1.66667 7 | -------------------------------------------------------------------------------- /testdata/gawk/getnr2tm.awk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/getnr2tm.awk -------------------------------------------------------------------------------- /testdata/gawk/getnr2tm.in: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /testdata/gawk/getnr2tm.ok: -------------------------------------------------------------------------------- 1 | 1 lines in 1 sec: 1 lines/sec; nlines=1 2 | -------------------------------------------------------------------------------- /testdata/gawk/gsubasgn.awk: -------------------------------------------------------------------------------- 1 | # tests for assigning to a function within that function 2 | 3 | #1 - should be bad 4 | function test1 (r) { gsub(r, "x", test1) } 5 | BEGIN { test1("") } 6 | -------------------------------------------------------------------------------- /testdata/gawk/gsubasgn.ok: -------------------------------------------------------------------------------- 1 | parse error at 4:35: global var "test1" can't also be a function -------------------------------------------------------------------------------- /testdata/gawk/gsubtest.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | str = "abc"; print gsub("b+", "FOO", str), str 3 | str = "abc"; print gsub("x*", "X", str), str 4 | str = "abc"; print gsub("b*", "X", str), str 5 | str = "abc"; print gsub("c", "X", str), str 6 | str = "abc"; print gsub("c+", "X", str), str 7 | str = "abc"; print gsub("x*$", "X", str), str 8 | str = "abc"; print gsub("b|$", "X", str), str 9 | } 10 | -------------------------------------------------------------------------------- /testdata/gawk/gsubtest.ok: -------------------------------------------------------------------------------- 1 | 1 aFOOc 2 | 4 XaXbXcX 3 | 3 XaXcX 4 | 1 abX 5 | 1 abX 6 | 1 abcX 7 | 2 aXcX 8 | -------------------------------------------------------------------------------- /testdata/gawk/gsubtst5.in: -------------------------------------------------------------------------------- 1 | This Is a Title: My Title? 2 | -------------------------------------------------------------------------------- /testdata/gawk/gsubtst5.ok: -------------------------------------------------------------------------------- 1 | ThisIsaTitleMyTitle 2 | -------------------------------------------------------------------------------- /testdata/gawk/gsubtst6.ok: -------------------------------------------------------------------------------- 1 | a:b:c:d 2 | -------------------------------------------------------------------------------- /testdata/gawk/gsubtst7.in: -------------------------------------------------------------------------------- 1 | aaa -------------------------------------------------------------------------------- /testdata/gawk/gsubtst7.ok: -------------------------------------------------------------------------------- 1 | aaa 2 | -------------------------------------------------------------------------------- /testdata/gawk/gsubtst8.awk: -------------------------------------------------------------------------------- 1 | { 2 | OFS = " " $2 " " 3 | gsub("foo", "_", OFS) 4 | print $1, $2 5 | } 6 | -------------------------------------------------------------------------------- /testdata/gawk/gsubtst8.in: -------------------------------------------------------------------------------- 1 | a bar b 2 | c foo d 3 | -------------------------------------------------------------------------------- /testdata/gawk/gsubtst8.ok: -------------------------------------------------------------------------------- 1 | a bar bar 2 | c _ foo 3 | -------------------------------------------------------------------------------- /testdata/gawk/hex.awk: -------------------------------------------------------------------------------- 1 | # Test program from Paul Eggert, eggert@cs.ucla.edu, Jan. 14, 2005 2 | 3 | BEGIN { 4 | e = "1(e)" 5 | ex = "3e2(ex)" 6 | x = "6e5(x)" 7 | 8 | print e+0, x+0 9 | print 0x 10 | # print 0e+x # GoAWK behaviour is different (saner!) here 11 | # print 0ex # GoAWK behaviour is different (saner!) here 12 | print 010e2 13 | print 0e9.3 14 | } 15 | 16 | # Expected results: 17 | # 1 600000 18 | # 06e5(x) 19 | # 0600001 20 | # 03e2(ex) 21 | # 1000 22 | # 00.3 23 | -------------------------------------------------------------------------------- /testdata/gawk/hex.ok: -------------------------------------------------------------------------------- 1 | 1 600000 2 | 06e5(x) 3 | 1000 4 | 00.3 5 | -------------------------------------------------------------------------------- /testdata/gawk/hex2.awk: -------------------------------------------------------------------------------- 1 | { print $1 + 7} 2 | -------------------------------------------------------------------------------- /testdata/gawk/hex2.in: -------------------------------------------------------------------------------- 1 | 0x4 2 | -0x4 3 | -------------------------------------------------------------------------------- /testdata/gawk/hex2.ok: -------------------------------------------------------------------------------- 1 | 7 2 | 7 3 | -------------------------------------------------------------------------------- /testdata/gawk/inpref.awk: -------------------------------------------------------------------------------- 1 | function test(x) { 2 | print x 3 | getline 4 | print x 5 | } 6 | 7 | { 8 | test($0) 9 | } 10 | -------------------------------------------------------------------------------- /testdata/gawk/inpref.in: -------------------------------------------------------------------------------- 1 | hello 2 | goodbye 3 | -------------------------------------------------------------------------------- /testdata/gawk/inpref.ok: -------------------------------------------------------------------------------- 1 | hello 2 | hello 3 | -------------------------------------------------------------------------------- /testdata/gawk/inputred.awk: -------------------------------------------------------------------------------- 1 | BEGIN { print getline < "file" ".txt" } 2 | -------------------------------------------------------------------------------- /testdata/gawk/inputred.ok: -------------------------------------------------------------------------------- 1 | -1.txt 2 | -------------------------------------------------------------------------------- /testdata/gawk/intest.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | bool = ((b = 1) in c); 3 | print bool, b # gawk-3.0.1 prints "0 "; should print "0 1" 4 | } 5 | -------------------------------------------------------------------------------- /testdata/gawk/intest.ok: -------------------------------------------------------------------------------- 1 | 0 1 2 | -------------------------------------------------------------------------------- /testdata/gawk/intprec.awk: -------------------------------------------------------------------------------- 1 | BEGIN { printf "%.10d:%.10x\n", 5, 14 } 2 | -------------------------------------------------------------------------------- /testdata/gawk/intprec.ok: -------------------------------------------------------------------------------- 1 | 0000000005:000000000e 2 | -------------------------------------------------------------------------------- /testdata/gawk/iobug1.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/iobug1.ok -------------------------------------------------------------------------------- /testdata/gawk/leaddig.awk: -------------------------------------------------------------------------------- 1 | # check that values with leading digits get converted the 2 | # right way, based on a note in comp.lang.awk. 3 | # 4 | # run with gawk -v x=2E -f leaddig.awk 5 | 6 | BEGIN { 7 | # 4/2018: Put it into the program to make generation of the 8 | # recipe automatable 9 | x = "2E" 10 | 11 | print "x =", x, (x == 2), (x == 2E0), (x == 2E), (x == 2D) 12 | } 13 | -------------------------------------------------------------------------------- /testdata/gawk/leaddig.ok: -------------------------------------------------------------------------------- 1 | x = 2E 0 0 0 0 2 | -------------------------------------------------------------------------------- /testdata/gawk/leadnl.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | RS = ""; FS = "\n" 3 | } 4 | 5 | { 6 | print "Name is: ", $1 7 | print "Address is: ", $2 8 | print "City and State are: ", $3 9 | print "" 10 | } 11 | -------------------------------------------------------------------------------- /testdata/gawk/leadnl.in: -------------------------------------------------------------------------------- 1 | 2 | Jane Doe 3 | 123 Main Street 4 | Anywhere, SE 12345-6789 5 | 6 | John Smith 7 | 456 Tree-lined Avenue 8 | Smallville, MW 98765-4321 9 | 10 | -------------------------------------------------------------------------------- /testdata/gawk/leadnl.ok: -------------------------------------------------------------------------------- 1 | Name is: Jane Doe 2 | Address is: 123 Main Street 3 | City and State are: Anywhere, SE 12345-6789 4 | 5 | Name is: John Smith 6 | Address is: 456 Tree-lined Avenue 7 | City and State are: Smallville, MW 98765-4321 8 | 9 | -------------------------------------------------------------------------------- /testdata/gawk/litoct.awk: -------------------------------------------------------------------------------- 1 | { if (/a\52b/) print "match" ; else print "no match" } 2 | -------------------------------------------------------------------------------- /testdata/gawk/litoct.in: -------------------------------------------------------------------------------- 1 | ab 2 | -------------------------------------------------------------------------------- /testdata/gawk/litoct.ok: -------------------------------------------------------------------------------- 1 | no match 2 | -------------------------------------------------------------------------------- /testdata/gawk/longsub.awk: -------------------------------------------------------------------------------- 1 | {sub( "^.*AA", "BB"); print} 2 | -------------------------------------------------------------------------------- /testdata/gawk/longwrds.ok: -------------------------------------------------------------------------------- 1 | 20 long words 2 | compatibility 3 | concatenated 4 | consistency 5 | definitions 6 | description 7 | distributing 8 | fistatements 9 | gawk-options 10 | gnu-specific 11 | identically 12 | implementation 13 | implementations 14 | information 15 | non-portable 16 | pattern-action 17 | pre-defined 18 | program-file 19 | program-text 20 | programming 21 | restrictions 22 | -------------------------------------------------------------------------------- /testdata/gawk/manglprm.in: -------------------------------------------------------------------------------- 1 | Testing 2 | -------------------------------------------------------------------------------- /testdata/gawk/manglprm.ok: -------------------------------------------------------------------------------- 1 | Buffer = [] 2 | -------------------------------------------------------------------------------- /testdata/gawk/math.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | pi = 3.1415927 3 | printf "cos(%f) = %f\n", pi/4, cos(pi/4) 4 | printf "sin(%f) = %f\n", pi/4, sin(pi/4) 5 | e = exp(1) 6 | printf "e = %f\n", e 7 | printf "log(e) = %f\n", log(e) 8 | printf "sqrt(pi ^ 2) = %f\n", sqrt(pi ^ 2) 9 | printf "atan2(1, 1) = %f\n", atan2(1, 1) 10 | } 11 | -------------------------------------------------------------------------------- /testdata/gawk/math.ok: -------------------------------------------------------------------------------- 1 | cos(0.785398) = 0.707107 2 | sin(0.785398) = 0.707107 3 | e = 2.718282 4 | log(e) = 1.000000 5 | sqrt(pi ^ 2) = 3.141593 6 | atan2(1, 1) = 0.785398 7 | -------------------------------------------------------------------------------- /testdata/gawk/minusstr.awk: -------------------------------------------------------------------------------- 1 | BEGIN { print-"6" } 2 | -------------------------------------------------------------------------------- /testdata/gawk/minusstr.ok: -------------------------------------------------------------------------------- 1 | -6 2 | -------------------------------------------------------------------------------- /testdata/gawk/mmap8k.awk: -------------------------------------------------------------------------------- 1 | { print } 2 | -------------------------------------------------------------------------------- /testdata/gawk/nasty.ok: -------------------------------------------------------------------------------- 1 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 2 | X 3 | -------------------------------------------------------------------------------- /testdata/gawk/nasty2.awk: -------------------------------------------------------------------------------- 1 | # Based on nasty.awk, test same thing for printf 2 | # 3 | BEGIN { 4 | a="aaaaa" 5 | a=a a #10 6 | a=a a #20 7 | a=a a #40 8 | a=a a #80 9 | a=a a #160 10 | a=a a # i.e. a is long enough 11 | 12 | printf("a = %s, f() = %s\n", a, f()) 13 | print a 14 | } 15 | 16 | function f() 17 | { 18 | gsub(/a/, "123", a) 19 | return "X" 20 | } 21 | -------------------------------------------------------------------------------- /testdata/gawk/negexp.awk: -------------------------------------------------------------------------------- 1 | BEGIN { a = -2; print 10^a } 2 | -------------------------------------------------------------------------------- /testdata/gawk/negexp.ok: -------------------------------------------------------------------------------- 1 | 0.01 2 | -------------------------------------------------------------------------------- /testdata/gawk/negrange.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | s = "Volume 8, Numbers 1-2 / January 1971" 3 | n = split(s, parts, "[^-A-Za-z0-9]+") 4 | print "n =", n 5 | for (i = 1; i <= n; i++) 6 | printf("s[%d] = \"%s\"\n", i, parts[i]) 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/negrange.ok: -------------------------------------------------------------------------------- 1 | n = 6 2 | s[1] = "Volume" 3 | s[2] = "8" 4 | s[3] = "Numbers" 5 | s[4] = "1-2" 6 | s[5] = "January" 7 | s[6] = "1971" 8 | -------------------------------------------------------------------------------- /testdata/gawk/nested.in: -------------------------------------------------------------------------------- 1 | a_b 2 | -------------------------------------------------------------------------------- /testdata/gawk/nested.ok: -------------------------------------------------------------------------------- 1 | a 2 | a 3 | -------------------------------------------------------------------------------- /testdata/gawk/nfldstr.awk: -------------------------------------------------------------------------------- 1 | $1 == 0 { 2 | print "bug" 3 | } 4 | { 5 | $0 = "0" 6 | if (!$0) 7 | print "another bug" 8 | $0 = a = "0" 9 | if (!$0) 10 | print "yet another bug" 11 | if ($1) 12 | print "a buggie" 13 | } 14 | -------------------------------------------------------------------------------- /testdata/gawk/nfldstr.in: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testdata/gawk/nfldstr.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/nfldstr.ok -------------------------------------------------------------------------------- /testdata/gawk/nfloop.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | $0 = "aaa" 3 | NF = 10 4 | for (j = 2; j <= NF; ++j) { 5 | $j = "_" 6 | } 7 | print 8 | } 9 | -------------------------------------------------------------------------------- /testdata/gawk/nfloop.ok: -------------------------------------------------------------------------------- 1 | aaa _ _ _ _ _ _ _ _ _ 2 | -------------------------------------------------------------------------------- /testdata/gawk/nfneg.awk: -------------------------------------------------------------------------------- 1 | BEGIN { NF -= 2 ; print } 2 | -------------------------------------------------------------------------------- /testdata/gawk/nfneg.ok: -------------------------------------------------------------------------------- 1 | NF set to negative value: -2 -------------------------------------------------------------------------------- /testdata/gawk/nfset.awk: -------------------------------------------------------------------------------- 1 | { NF = 5 ; print } 2 | -------------------------------------------------------------------------------- /testdata/gawk/nfset.in: -------------------------------------------------------------------------------- 1 | 1 2 2 | 1 2 3 4 3 | 1 2 3 4 5 4 | 1 2 3 4 5 6 7 8 5 | 1 6 | -------------------------------------------------------------------------------- /testdata/gawk/nfset.ok: -------------------------------------------------------------------------------- 1 | 1 2 2 | 1 2 3 4 3 | 1 2 3 4 5 4 | 1 2 3 4 5 5 | 1 6 | -------------------------------------------------------------------------------- /testdata/gawk/nlfldsep.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "A" } 2 | {print NF; for (i = 1; i <= NF; i++) print $i ; print ""} 3 | -------------------------------------------------------------------------------- /testdata/gawk/nlfldsep.in: -------------------------------------------------------------------------------- 1 | some stuff 2 | more stuffA 3 | junk 4 | stuffA 5 | final 6 | -------------------------------------------------------------------------------- /testdata/gawk/nlfldsep.ok: -------------------------------------------------------------------------------- 1 | 4 2 | some 3 | stuff 4 | more 5 | stuff 6 | 7 | 2 8 | junk 9 | stuff 10 | 11 | 1 12 | final 13 | 14 | -------------------------------------------------------------------------------- /testdata/gawk/nlinstr.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "" } 2 | 3 | { 4 | if (/^@/) 5 | print "not ok" 6 | else 7 | print "ok" 8 | } 9 | -------------------------------------------------------------------------------- /testdata/gawk/nlinstr.in: -------------------------------------------------------------------------------- 1 | line 1 2 | @line 2 3 | -------------------------------------------------------------------------------- /testdata/gawk/nlinstr.ok: -------------------------------------------------------------------------------- 1 | ok 2 | -------------------------------------------------------------------------------- /testdata/gawk/nlstrina.ok: -------------------------------------------------------------------------------- 1 | a 2 2 2 | b 3 3 3 | c 1 3 4 | -------------------------------------------------------------------------------- /testdata/gawk/noeffect.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | s == "hello, world"; 3 | s + 1 4 | ;; 5 | "s" 1 6 | "a" 7 | 42 8 | q = 42 9 | q 10 | } 11 | -------------------------------------------------------------------------------- /testdata/gawk/noeffect.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/noeffect.ok -------------------------------------------------------------------------------- /testdata/gawk/nofmtch.awk: -------------------------------------------------------------------------------- 1 | BEGIN { printf "%3\n" } 2 | -------------------------------------------------------------------------------- /testdata/gawk/nofmtch.ok: -------------------------------------------------------------------------------- 1 | format error: invalid format type '\n' -------------------------------------------------------------------------------- /testdata/gawk/noloop1.in: -------------------------------------------------------------------------------- 1 | ''Italics with an apostrophe'' embedded'' 2 | -------------------------------------------------------------------------------- /testdata/gawk/noloop1.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/noloop1.ok -------------------------------------------------------------------------------- /testdata/gawk/noloop2.in: -------------------------------------------------------------------------------- 1 | ''Italics with an apostrophe' embedded'' 2 | -------------------------------------------------------------------------------- /testdata/gawk/noloop2.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/noloop2.ok -------------------------------------------------------------------------------- /testdata/gawk/nonl.awk: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testdata/gawk/nonl.in: -------------------------------------------------------------------------------- 1 | junk -------------------------------------------------------------------------------- /testdata/gawk/nonl.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/nonl.ok -------------------------------------------------------------------------------- /testdata/gawk/noparms.awk: -------------------------------------------------------------------------------- 1 | function x(a, b, c , ,) {} 2 | -------------------------------------------------------------------------------- /testdata/gawk/noparms.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:22: expected name instead of , -------------------------------------------------------------------------------- /testdata/gawk/nulinsrc.awk: -------------------------------------------------------------------------------- 1 | /\ -------------------------------------------------------------------------------- /testdata/gawk/nulinsrc.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:4: didn't find end slash in regex -------------------------------------------------------------------------------- /testdata/gawk/nulrsend.in: -------------------------------------------------------------------------------- 1 | 1111 2 | 3 | 2222 4 | 5 | -------------------------------------------------------------------------------- /testdata/gawk/nulrsend.ok: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /testdata/gawk/numindex.in: -------------------------------------------------------------------------------- 1 | 322322111111112232231111 2 | 322322111111112213223111 3 | 322322111111112211132231 4 | 322322111111112211113223 5 | -------------------------------------------------------------------------------- /testdata/gawk/numindex.ok: -------------------------------------------------------------------------------- 1 | 0 0.000000% 2 | -------------------------------------------------------------------------------- /testdata/gawk/numrange.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | n = split("-1.2e+931 1.2e+931", a) 3 | for (i=1; i<=n; ++i) 4 | print a[i], +a[i] 5 | } 6 | -------------------------------------------------------------------------------- /testdata/gawk/numrange.ok: -------------------------------------------------------------------------------- 1 | -1.2e+931 -inf 2 | 1.2e+931 inf 3 | -------------------------------------------------------------------------------- /testdata/gawk/numstr1.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | split("1.234", f) 3 | OFMT = "%.1f" 4 | print f[1] 5 | x = f[1]+0 6 | print f[1] 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/numstr1.ok: -------------------------------------------------------------------------------- 1 | 1.234 2 | 1.234 3 | -------------------------------------------------------------------------------- /testdata/gawk/numsubstr.awk: -------------------------------------------------------------------------------- 1 | { print substr(1000+$1, 2) } 2 | -------------------------------------------------------------------------------- /testdata/gawk/numsubstr.in: -------------------------------------------------------------------------------- 1 | 5000 2 | 10000 3 | 5000 4 | -------------------------------------------------------------------------------- /testdata/gawk/numsubstr.ok: -------------------------------------------------------------------------------- 1 | 000 2 | 1000 3 | 000 4 | -------------------------------------------------------------------------------- /testdata/gawk/octsub.awk: -------------------------------------------------------------------------------- 1 | BEGIN{ ++x[03]; print "/" x[0] "/" x[3] "/"} 2 | -------------------------------------------------------------------------------- /testdata/gawk/octsub.ok: -------------------------------------------------------------------------------- 1 | //1/ 2 | -------------------------------------------------------------------------------- /testdata/gawk/ofmt.ok: -------------------------------------------------------------------------------- 1 | alt/binaries/warez/crypto - - 2 | alt/fan/douglas-adams 7491 7407 3 | alt/os/linux - - 4 | alt/security 9641 9617 5 | alt/security/index - - 6 | alt/security/keydist 253 253 7 | -------------------------------------------------------------------------------- /testdata/gawk/ofmta.ok: -------------------------------------------------------------------------------- 1 | 4.2 2 | 4.2345 hi 3 | hi 4 | -------- 5 | 4.234 6 | 4.2345 hi 7 | 8 | -------------------------------------------------------------------------------- /testdata/gawk/ofmtbig.in: -------------------------------------------------------------------------------- 1 | a 2 | 1 3 | b 4 | -------------------------------------------------------------------------------- /testdata/gawk/ofmtbig.ok: -------------------------------------------------------------------------------- 1 | 0 99999999999 2 | a 1 1 3 | -------------------------------------------------------------------------------- /testdata/gawk/ofmtfidl.in: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /testdata/gawk/ofmtfidl.ok: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /testdata/gawk/ofmts.awk: -------------------------------------------------------------------------------- 1 | BEGIN { OFMT= "%s" } 2 | { $1 + $2; print $1, $2 } 3 | -------------------------------------------------------------------------------- /testdata/gawk/ofmts.in: -------------------------------------------------------------------------------- 1 | 1.2 2.2 2 | -------------------------------------------------------------------------------- /testdata/gawk/ofmts.ok: -------------------------------------------------------------------------------- 1 | 1.2 2.2 2 | -------------------------------------------------------------------------------- /testdata/gawk/ofmtstrnum.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | split(" 1", f, "x") 3 | OFMT = "%.1f" 4 | print f[1] 5 | x = f[1] + 0 6 | print f[1] 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/ofmtstrnum.ok: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | -------------------------------------------------------------------------------- /testdata/gawk/ofs1.in: -------------------------------------------------------------------------------- 1 | a:b:c 2 | a:b:c 3 | a:b:c 4 | a:b:c 5 | -------------------------------------------------------------------------------- /testdata/gawk/ofs1.ok: -------------------------------------------------------------------------------- 1 | a x c 2 | a x c 3 | a x c 4 | a 5 | a x c 6 | a x c 7 | a x c 8 | -------------------------------------------------------------------------------- /testdata/gawk/onlynl.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "" } 2 | { print "got", $0 } 3 | -------------------------------------------------------------------------------- /testdata/gawk/onlynl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /testdata/gawk/onlynl.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/onlynl.ok -------------------------------------------------------------------------------- /testdata/gawk/opasnidx.awk: -------------------------------------------------------------------------------- 1 | BEGIN { b = 1; a[b] = 2; a[b++] += 1; print b,a[1] } 2 | -------------------------------------------------------------------------------- /testdata/gawk/opasnidx.ok: -------------------------------------------------------------------------------- 1 | 2 3 2 | -------------------------------------------------------------------------------- /testdata/gawk/opasnslf.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | print b += b += 1 3 | b = 6 4 | print b += b++ 5 | print b 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/opasnslf.ok: -------------------------------------------------------------------------------- 1 | 2 2 | 13 3 | 13 4 | -------------------------------------------------------------------------------- /testdata/gawk/paramasfunc1.awk: -------------------------------------------------------------------------------- 1 | BEGIN{ X() } 2 | 3 | function X( abc) 4 | { 5 | abc = "stamp out " 6 | print abc abc() 7 | } 8 | 9 | function abc() { return "dark corners" } 10 | -------------------------------------------------------------------------------- /testdata/gawk/paramasfunc1.ok: -------------------------------------------------------------------------------- 1 | parse error at 6:12: can't call local variable "abc" as function -------------------------------------------------------------------------------- /testdata/gawk/paramasfunc2.awk: -------------------------------------------------------------------------------- 1 | BEGIN{ X() } 2 | 3 | function abc() { return "dark corners" } 4 | 5 | function X( abc) 6 | { 7 | abc = "stamp out " 8 | print abc abc() 9 | } 10 | 11 | -------------------------------------------------------------------------------- /testdata/gawk/paramasfunc2.ok: -------------------------------------------------------------------------------- 1 | parse error at 8:12: can't call local variable "abc" as function -------------------------------------------------------------------------------- /testdata/gawk/paramdup.awk: -------------------------------------------------------------------------------- 1 | BEGIN { foo(0, 1, 2) } 2 | 3 | function foo(a, b, c, b, a) 4 | { 5 | print "a =", a 6 | print "b =", b 7 | print "c =", c 8 | } 9 | -------------------------------------------------------------------------------- /testdata/gawk/paramdup.ok: -------------------------------------------------------------------------------- 1 | parse error at 3:23: duplicate parameter name "b" -------------------------------------------------------------------------------- /testdata/gawk/paramtyp.awk: -------------------------------------------------------------------------------- 1 | # Sun Apr 25 13:28:58 IDT 1999 2 | # from Juegen Khars. This program should not core dump. 3 | function ReadPGM(f, d) { 4 | print "ReadPGM" 5 | d[1] = 1 6 | } 7 | 8 | function WritePGM(f, d) { 9 | print "WritePGM" 10 | d[1] = 0 11 | } 12 | 13 | BEGIN { 14 | print "before ReadPGM" 15 | ReadPGM("", d) 16 | print "after ReadPGM" 17 | print "before WritePGM" 18 | WritePGM("", d) 19 | print "after WritePGM" 20 | } 21 | -------------------------------------------------------------------------------- /testdata/gawk/paramtyp.ok: -------------------------------------------------------------------------------- 1 | before ReadPGM 2 | ReadPGM 3 | after ReadPGM 4 | before WritePGM 5 | WritePGM 6 | after WritePGM 7 | -------------------------------------------------------------------------------- /testdata/gawk/paramuninitglobal.awk: -------------------------------------------------------------------------------- 1 | function f(x) 2 | { 3 | a = 10 4 | x = 90 5 | print x 6 | print a 7 | a++ 8 | x++ 9 | print x 10 | } 11 | 12 | BEGIN { 13 | f(a) 14 | print a 15 | } 16 | -------------------------------------------------------------------------------- /testdata/gawk/paramuninitglobal.ok: -------------------------------------------------------------------------------- 1 | 90 2 | 10 3 | 91 4 | 11 5 | -------------------------------------------------------------------------------- /testdata/gawk/parse1.in: -------------------------------------------------------------------------------- 1 | 3 4 5 6 7 8 9 2 | -------------------------------------------------------------------------------- /testdata/gawk/parse1.ok: -------------------------------------------------------------------------------- 1 | in: 3 4 5 6 7 8 9 2 | a = 3 3 | 7 4 | out: 3 4 6 6 8 8 9 5 | -------------------------------------------------------------------------------- /testdata/gawk/parsefld.awk: -------------------------------------------------------------------------------- 1 | { print /a/ + /b/ + !/c/} 2 | -------------------------------------------------------------------------------- /testdata/gawk/parsefld.in: -------------------------------------------------------------------------------- 1 | a = b 2 | -------------------------------------------------------------------------------- /testdata/gawk/parsefld.ok: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testdata/gawk/parseme.awk: -------------------------------------------------------------------------------- 1 | BEGIN { toupper(substr*line,1,12)) } 2 | -------------------------------------------------------------------------------- /testdata/gawk/parseme.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:23: expected ( instead of * -------------------------------------------------------------------------------- /testdata/gawk/pcntplus.awk: -------------------------------------------------------------------------------- 1 | BEGIN { printf "%+d %d\n", 3, 4 } 2 | -------------------------------------------------------------------------------- /testdata/gawk/pcntplus.ok: -------------------------------------------------------------------------------- 1 | +3 4 2 | -------------------------------------------------------------------------------- /testdata/gawk/posix2008sub.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | text = "here is some text" 3 | repl = "" 4 | printf "orig = \"%s\", repl = \"%s\"\n", text, repl 5 | sub(/some/, repl, text) 6 | printf "result is \"%s\"\n", text 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/posix2008sub.ok: -------------------------------------------------------------------------------- 1 | orig = "here is some text", repl = "" 2 | result is "here is text" 3 | -------------------------------------------------------------------------------- /testdata/gawk/prdupval.awk: -------------------------------------------------------------------------------- 1 | { print NF, $NF, "abc" $NF } 2 | -------------------------------------------------------------------------------- /testdata/gawk/prdupval.in: -------------------------------------------------------------------------------- 1 | one 2 | -------------------------------------------------------------------------------- /testdata/gawk/prdupval.ok: -------------------------------------------------------------------------------- 1 | 1 one abcone 2 | -------------------------------------------------------------------------------- /testdata/gawk/prec.awk: -------------------------------------------------------------------------------- 1 | # check the precedence of operators: 2 | BEGIN { 3 | $1 = i = 1 4 | $+i++ 5 | $- -i++ 6 | print 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/prec.ok: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/gawk/printf1.ok: -------------------------------------------------------------------------------- 1 | %8.5d, 100 --- | 00100| 2 | %#o, 0 --- |0| 3 | %#.1o, 0 --- |0| 4 | %#.0o, 0 --- || 5 | %#x, 0 --- |0x0| 6 | %.0d, 0 --- || 7 | %5.0d, 0 --- | | 8 | -------------------------------------------------------------------------------- /testdata/gawk/printfchar.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | x[65] = 1; 3 | for (i in x) { 4 | # i should be a string 5 | printf "%c\n", i # should print 1st char of string 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/printfchar.ok: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /testdata/gawk/prmarscl.awk: -------------------------------------------------------------------------------- 1 | function test(a) 2 | { 3 | print a[1] 4 | } 5 | 6 | BEGIN { j = 4; test(j) } 7 | -------------------------------------------------------------------------------- /testdata/gawk/prmarscl.ok: -------------------------------------------------------------------------------- 1 | parse error at 6:21: can't pass scalar "j" as array param -------------------------------------------------------------------------------- /testdata/gawk/prmreuse.awk: -------------------------------------------------------------------------------- 1 | # from Pat Rankin, rankin@eql.caltech.edu, now rankin@pactechdata.com 2 | 3 | BEGIN { dummy(1); legit(); exit } 4 | 5 | function dummy(arg) 6 | { 7 | return arg 8 | } 9 | 10 | function legit( scratch) 11 | { 12 | split("1 2 3", scratch) 13 | return "" 14 | } 15 | -------------------------------------------------------------------------------- /testdata/gawk/prmreuse.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/prmreuse.ok -------------------------------------------------------------------------------- /testdata/gawk/prt1eval.awk: -------------------------------------------------------------------------------- 1 | function tst () { 2 | sum += 1 3 | return sum 4 | } 5 | 6 | BEGIN { OFMT = "%.0f" ; print tst() } 7 | -------------------------------------------------------------------------------- /testdata/gawk/prt1eval.ok: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testdata/gawk/prtoeval.awk: -------------------------------------------------------------------------------- 1 | function returns_a_str() { print "" ; return "'A STRING'" } 2 | BEGIN { 3 | print "partial line:", returns_a_str() 4 | } 5 | -------------------------------------------------------------------------------- /testdata/gawk/prtoeval.ok: -------------------------------------------------------------------------------- 1 | 2 | partial line: 'A STRING' 3 | -------------------------------------------------------------------------------- /testdata/gawk/rand.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | srand(2) 3 | for (i = 0; i < 19; i++) 4 | printf "%3d ", (1 + int(100 * rand())) 5 | print "" 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/rand.ok: -------------------------------------------------------------------------------- 1 | 61 95 67 44 43 69 7 16 10 31 52 82 22 39 32 47 29 30 68 2 | -------------------------------------------------------------------------------- /testdata/gawk/range1.awk: -------------------------------------------------------------------------------- 1 | /foo/,/bar/ { print } 2 | -------------------------------------------------------------------------------- /testdata/gawk/range1.in: -------------------------------------------------------------------------------- 1 | foobar 2 | junk 3 | -------------------------------------------------------------------------------- /testdata/gawk/range1.ok: -------------------------------------------------------------------------------- 1 | foobar 2 | -------------------------------------------------------------------------------- /testdata/gawk/readbuf.awk: -------------------------------------------------------------------------------- 1 | 2 | { 3 | -------------------------------------------------------------------------------- /testdata/gawk/readbuf.ok: -------------------------------------------------------------------------------- 1 | parse error at 3:1: expected } instead of EOF -------------------------------------------------------------------------------- /testdata/gawk/rebuild.awk: -------------------------------------------------------------------------------- 1 | { 2 | $1 = "test" 3 | print $0 4 | } 5 | -------------------------------------------------------------------------------- /testdata/gawk/rebuild.in: -------------------------------------------------------------------------------- 1 | a 6.3 2 | -------------------------------------------------------------------------------- /testdata/gawk/rebuild.ok: -------------------------------------------------------------------------------- 1 | test 6.3 2 | -------------------------------------------------------------------------------- /testdata/gawk/redfilnm.in: -------------------------------------------------------------------------------- 1 | hello, world 2 | -------------------------------------------------------------------------------- /testdata/gawk/redfilnm.ok: -------------------------------------------------------------------------------- 1 | hello, world 2 | hello, world 3 | hello, world 4 | hello, world 5 | hello, world 6 | hello, world 7 | hello, world 8 | hello, world 9 | hello, world 10 | -------------------------------------------------------------------------------- /testdata/gawk/regeq.in: -------------------------------------------------------------------------------- 1 | sdgfa 2 | asdfds=a 3 | -------------------------------------------------------------------------------- /testdata/gawk/regeq.ok: -------------------------------------------------------------------------------- 1 | 0 2 | 7 3 | -------------------------------------------------------------------------------- /testdata/gawk/regexpbrack.awk: -------------------------------------------------------------------------------- 1 | /[]+()0-9.,$%/'"-]*$/ 2 | /^[]+()0-9.,$%/'"-]*$/ 3 | -------------------------------------------------------------------------------- /testdata/gawk/regexpbrack.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/regexpbrack.in -------------------------------------------------------------------------------- /testdata/gawk/regexpbrack.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:1: error parsing regexp: missing closing ]: `[]+()0-9.,$%)` -------------------------------------------------------------------------------- /testdata/gawk/regexpbrack2.awk: -------------------------------------------------------------------------------- 1 | NR == 1 { gsub(/\\\\[;?!,()<>|+@%\]\[]/, " ") ; print "\"" $0 "\"" } 2 | NR == 2 { gsub(/\\\\[;?!,()<>|+@%\]\[^]/, " ") ; print "\"" $0 "\"" } 3 | -------------------------------------------------------------------------------- /testdata/gawk/regexpbrack2.in: -------------------------------------------------------------------------------- 1 | test: \\; \\? \\! 2 | test: \\; \\? \\! 3 | -------------------------------------------------------------------------------- /testdata/gawk/regexpbrack2.ok: -------------------------------------------------------------------------------- 1 | "test: " 2 | "test: " 3 | -------------------------------------------------------------------------------- /testdata/gawk/regexprange.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | range = "[a-dx-z]" 3 | 4 | split("ABCDEFGHIJKLMNOPQRSTUVWXYZ", upper, "") 5 | split("abcdefghijklmnopqrstuvwxyz", lower, "") 6 | 7 | for (i = 1; i in upper; i++) 8 | printf("%s ~ %s ---> %s\n", 9 | upper[i], range, (upper[i] ~ range) ? "true" : "false") 10 | 11 | for (i = 1; i in lower; i++) 12 | printf("%s ~ %s ---> %s\n", 13 | lower[i], range, (lower[i] ~ range) ? "true" : "false") 14 | } 15 | -------------------------------------------------------------------------------- /testdata/gawk/regrange.ok: -------------------------------------------------------------------------------- 1 | "." ~ /[--\/]/ --> 1 2 | "a" ~ /[]-c]/ --> 1 3 | "c" ~ /[[a-d]/ --> 1 4 | "\" ~ /[\[-\]]/ --> 1 5 | invalid regex "[a-[.e.]]": error parsing regexp: invalid character class range: `a-[` -------------------------------------------------------------------------------- /testdata/gawk/reparse.awk: -------------------------------------------------------------------------------- 1 | { 2 | gsub(/x/, " ") 3 | $0 = $0 4 | print $1 5 | print $0 6 | print $1, $2, $3 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/reparse.in: -------------------------------------------------------------------------------- 1 | 1 axbxc 2 2 | -------------------------------------------------------------------------------- /testdata/gawk/reparse.ok: -------------------------------------------------------------------------------- 1 | 1 2 | 1 a b c 2 3 | 1 a b 4 | -------------------------------------------------------------------------------- /testdata/gawk/resplit.awk: -------------------------------------------------------------------------------- 1 | { FS = ":"; $0 = $0; print $2 } 2 | -------------------------------------------------------------------------------- /testdata/gawk/resplit.in: -------------------------------------------------------------------------------- 1 | a:b:c d:e:f 2 | -------------------------------------------------------------------------------- /testdata/gawk/resplit.ok: -------------------------------------------------------------------------------- 1 | b 2 | -------------------------------------------------------------------------------- /testdata/gawk/rri1.awk: -------------------------------------------------------------------------------- 1 | /[d-f]/ 2 | -------------------------------------------------------------------------------- /testdata/gawk/rri1.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/rri1.in -------------------------------------------------------------------------------- /testdata/gawk/rri1.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/rri1.ok -------------------------------------------------------------------------------- /testdata/gawk/rs.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "" } 2 | { print $1, $2 } 3 | -------------------------------------------------------------------------------- /testdata/gawk/rs.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | a 4 | b 5 | 6 | 7 | c d 8 | 9 | 10 | 11 | e 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /testdata/gawk/rs.ok: -------------------------------------------------------------------------------- 1 | a b 2 | c d 3 | e 4 | -------------------------------------------------------------------------------- /testdata/gawk/rscompat.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "bar" } 2 | { print $1, $2 } 3 | -------------------------------------------------------------------------------- /testdata/gawk/rscompat.in: -------------------------------------------------------------------------------- 1 | 0foobar0faz 2 | 1foobar1faz 3 | -------------------------------------------------------------------------------- /testdata/gawk/rscompat.ok: -------------------------------------------------------------------------------- 1 | 0foo 2 | ar0faz 1foo 3 | ar1faz 4 | -------------------------------------------------------------------------------- /testdata/gawk/rsgetline.in: -------------------------------------------------------------------------------- 1 | 1,2, -------------------------------------------------------------------------------- /testdata/gawk/rsgetline.ok: -------------------------------------------------------------------------------- 1 | [1] [,] 2 | -1- 3 | [2] [,] 4 | -------------------------------------------------------------------------------- /testdata/gawk/rsnul1nl.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "" } 2 | { print } 3 | -------------------------------------------------------------------------------- /testdata/gawk/rsnul1nl.in: -------------------------------------------------------------------------------- 1 | 2 | This is... 3 | the first record. 4 | -------------------------------------------------------------------------------- /testdata/gawk/rsnul1nl.ok: -------------------------------------------------------------------------------- 1 | This is... 2 | the first record. 3 | -------------------------------------------------------------------------------- /testdata/gawk/rsnullre.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | RS = "()" 3 | } 4 | 5 | { printf("<<%s>>\n", $0) ; printf("<%s>\n", RT) } 6 | -------------------------------------------------------------------------------- /testdata/gawk/rsnullre.in: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /testdata/gawk/rsnullre.ok: -------------------------------------------------------------------------------- 1 | <> 3 | <> 4 | -------------------------------------------------------------------------------- /testdata/gawk/rsnulw.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "" } 2 | 3 | { 4 | print NF, "<" $0 ":" RT ">" 5 | for (i = 1; i <= NF; i++) 6 | print i, "[" $i "]" 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/rsnulw.in: -------------------------------------------------------------------------------- 1 | a b c 2 | -------------------------------------------------------------------------------- /testdata/gawk/rsnulw.ok: -------------------------------------------------------------------------------- 1 | 3 < a b c : 2 | > 3 | 1 [a] 4 | 2 [b] 5 | 3 [c] 6 | -------------------------------------------------------------------------------- /testdata/gawk/rsstart1.ok: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testdata/gawk/rsstart2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "^Ax*\n" } 2 | END { print NR } 3 | -------------------------------------------------------------------------------- /testdata/gawk/rsstart2.ok: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testdata/gawk/rstest1.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | RS = "" 3 | FS = ":" 4 | s = "a:b\nc:d" 5 | print split(s,a) 6 | print length(a[2]) 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/rstest1.ok: -------------------------------------------------------------------------------- 1 | 3 2 | 3 3 | -------------------------------------------------------------------------------- /testdata/gawk/rstest2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | RS = "" 3 | FS = "\\" 4 | $0 = "a\\b" 5 | print $1 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/rstest2.ok: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /testdata/gawk/rstest3.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/rstest3.ok -------------------------------------------------------------------------------- /testdata/gawk/rstest4.ok: -------------------------------------------------------------------------------- 1 | y = 2 | x = <> 3 | -------------------------------------------------------------------------------- /testdata/gawk/rstest5.ok: -------------------------------------------------------------------------------- 1 | foo 2 | baz 3 | bar 4 | x = <> 5 | -------------------------------------------------------------------------------- /testdata/gawk/rstest6.awk: -------------------------------------------------------------------------------- 1 | # Wed Jul 14 16:02:45 IDT 2004 2 | # Test case from John Haque mary1john8@earthlink.net 3 | 4 | BEGIN { RS = "XYZ" } 5 | 6 | { print } 7 | -------------------------------------------------------------------------------- /testdata/gawk/rstest6.in: -------------------------------------------------------------------------------- 1 | ABCD -------------------------------------------------------------------------------- /testdata/gawk/rstest6.ok: -------------------------------------------------------------------------------- 1 | ABCD 2 | -------------------------------------------------------------------------------- /testdata/gawk/rswhite.awk: -------------------------------------------------------------------------------- 1 | BEGIN { RS = "" } 2 | { printf("<%s>\n", $0) } 3 | -------------------------------------------------------------------------------- /testdata/gawk/rswhite.in: -------------------------------------------------------------------------------- 1 | a b 2 | c d 3 | -------------------------------------------------------------------------------- /testdata/gawk/rswhite.ok: -------------------------------------------------------------------------------- 1 | < a b 2 | c d> 3 | -------------------------------------------------------------------------------- /testdata/gawk/scalar.awk: -------------------------------------------------------------------------------- 1 | BEGIN{ 2 | sub(/x/,"",a) 3 | a[1] 4 | } 5 | -------------------------------------------------------------------------------- /testdata/gawk/scalar.ok: -------------------------------------------------------------------------------- 1 | parse error at 3:2: can't use scalar "a" as array -------------------------------------------------------------------------------- /testdata/gawk/sclforin.awk: -------------------------------------------------------------------------------- 1 | BEGIN { j = 4; for (i in j) print j[i] } 2 | -------------------------------------------------------------------------------- /testdata/gawk/sclforin.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:26: can't use scalar "j" as array -------------------------------------------------------------------------------- /testdata/gawk/sclifin.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | j = 4 3 | if ("foo" in j) 4 | print "ouch" 5 | else 6 | print "ok" 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/sclifin.ok: -------------------------------------------------------------------------------- 1 | parse error at 3:15: can't use scalar "j" as array -------------------------------------------------------------------------------- /testdata/gawk/setrec0.awk: -------------------------------------------------------------------------------- 1 | function reassign(x, y) { 2 | $0 = x 3 | print y 4 | } 5 | 6 | { 7 | reassign("larry", $1) 8 | } 9 | -------------------------------------------------------------------------------- /testdata/gawk/setrec0.in: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /testdata/gawk/setrec0.ok: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /testdata/gawk/setrec1.awk: -------------------------------------------------------------------------------- 1 | function reassign(x, y) { 2 | $0 = x 3 | print y 4 | } 5 | 6 | BEGIN { 7 | $0 = substr("geronimo", 5, 3) 8 | reassign(" 52", $1) 9 | } 10 | -------------------------------------------------------------------------------- /testdata/gawk/setrec1.ok: -------------------------------------------------------------------------------- 1 | nim 2 | -------------------------------------------------------------------------------- /testdata/gawk/sigpipe1.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | print "system" 3 | command = "yes | true" 4 | system(command) 5 | 6 | print "pipe to command" 7 | print "hi" | command 8 | close(command) 9 | 10 | print "pipe from command" 11 | command | getline x 12 | close(command) 13 | } 14 | -------------------------------------------------------------------------------- /testdata/gawk/sigpipe1.ok: -------------------------------------------------------------------------------- 1 | system 2 | pipe to command 3 | pipe from command 4 | -------------------------------------------------------------------------------- /testdata/gawk/spacere.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | c[" "] = "\" \"" 3 | c["\a"] = "\\a" 4 | c["\b"] = "\\b" 5 | c["\f"] = "\\f" 6 | c["\n"] = "\\n" 7 | c["\r"] = "\\r" 8 | c["\t"] = "\\t" 9 | c["\v"] = "\\v" 10 | 11 | sort = "LC_ALL=C sort" 12 | 13 | for (i in c) 14 | printf("%s %s [[:space:]]\n", c[i], 15 | i ~ /[[:space:]]/ ? "~" : "!~") | sort 16 | 17 | for (i in c) 18 | printf("%s %s [[:blank:]]\n", c[i], 19 | i ~ /[[:blank:]]/ ? "~" : "!~") | sort 20 | 21 | close(sort) 22 | } 23 | -------------------------------------------------------------------------------- /testdata/gawk/spacere.ok: -------------------------------------------------------------------------------- 1 | " " ~ [[:blank:]] 2 | " " ~ [[:space:]] 3 | \a !~ [[:blank:]] 4 | \a !~ [[:space:]] 5 | \b !~ [[:blank:]] 6 | \b !~ [[:space:]] 7 | \f !~ [[:blank:]] 8 | \f ~ [[:space:]] 9 | \n !~ [[:blank:]] 10 | \n ~ [[:space:]] 11 | \r !~ [[:blank:]] 12 | \r ~ [[:space:]] 13 | \t ~ [[:blank:]] 14 | \t ~ [[:space:]] 15 | \v !~ [[:blank:]] 16 | \v ~ [[:space:]] 17 | -------------------------------------------------------------------------------- /testdata/gawk/splitargv.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | for (idx = 1; idx < ARGC; idx++) 3 | split(ARGV[idx], temp, "."); 4 | } 5 | { 6 | print $0; 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/splitargv.in: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | for (idx = 1; idx < ARGC; idx++) 3 | split(ARGV[idx], temp, "."); 4 | } 5 | { 6 | print $0; 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/splitargv.ok: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | for (idx = 1; idx < ARGC; idx++) 3 | split(ARGV[idx], temp, "."); 4 | } 5 | { 6 | print $0; 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/splitarr.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | a[1] = "elephantie" 3 | a[2] = "e" 4 | print split(a[1],a,a[2]), a[2], a[3], split(a[2],a,a[2]) 5 | } 6 | -------------------------------------------------------------------------------- /testdata/gawk/splitarr.ok: -------------------------------------------------------------------------------- 1 | 4 l phanti 2 2 | -------------------------------------------------------------------------------- /testdata/gawk/splitdef.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | data = "abc:easy:as:one:two:three" 3 | FS = ":" 4 | FIELDWIDTHS = "3 1 4 1 2 1 3 1 3 1 5" 5 | n = split(data, a) 6 | printf "n = %d, a[3] = %s\n", n, a[3] 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/splitdef.ok: -------------------------------------------------------------------------------- 1 | n = 6, a[3] = as 2 | -------------------------------------------------------------------------------- /testdata/gawk/splitvar.awk: -------------------------------------------------------------------------------- 1 | { 2 | sep = "=+" 3 | n = split($0, a, sep) 4 | print n 5 | } 6 | -------------------------------------------------------------------------------- /testdata/gawk/splitvar.in: -------------------------------------------------------------------------------- 1 | Here===Is=Some=====Data 2 | -------------------------------------------------------------------------------- /testdata/gawk/splitvar.ok: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /testdata/gawk/splitwht.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | str = "a b\t\tc d" 3 | n = split(str, a, " ") 4 | print n 5 | m = split(str, b, / /) 6 | print m 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/splitwht.ok: -------------------------------------------------------------------------------- 1 | 4 2 | 5 3 | -------------------------------------------------------------------------------- /testdata/gawk/status-close.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | cat = "cat ; exit 3" 3 | print system("echo xxx | (cat ; exit 4)") 4 | 5 | print "YYY" | cat 6 | 7 | print close(cat) 8 | 9 | echo = "echo boo ; exit 5" 10 | echo | getline boo 11 | print "got", boo 12 | 13 | print close(echo) 14 | } 15 | -------------------------------------------------------------------------------- /testdata/gawk/status-close.ok: -------------------------------------------------------------------------------- 1 | xxx 2 | 4 3 | YYY 4 | 3 5 | got boo 6 | 5 7 | -------------------------------------------------------------------------------- /testdata/gawk/strcat1.awk: -------------------------------------------------------------------------------- 1 | 2 | function f1(b) { b = b "c"; print f(b); } 3 | 4 | function f(a) { a = a "b"; return a; } 5 | 6 | BEGIN { A = "a"; f1(A); } 7 | -------------------------------------------------------------------------------- /testdata/gawk/strcat1.ok: -------------------------------------------------------------------------------- 1 | acb 2 | -------------------------------------------------------------------------------- /testdata/gawk/strnum1.ok: -------------------------------------------------------------------------------- 1 | 8 = 8 2 | 88 = 88 3 | -------------------------------------------------------------------------------- /testdata/gawk/strnum2.ok: -------------------------------------------------------------------------------- 1 | 1.234 2 | 1.234 3 | 1.234 4 | 1.234 5 | -------------------------------------------------------------------------------- /testdata/gawk/strtod.awk: -------------------------------------------------------------------------------- 1 | { 2 | x = "0x" $1 ; print x, x + 0 3 | for (i=1; i<=NF; i++) 4 | if ($i) print $i, "is not zero" 5 | } 6 | -------------------------------------------------------------------------------- /testdata/gawk/strtod.in: -------------------------------------------------------------------------------- 1 | 345 0 00 0e0 0E1 00E0 000e-5 .0e+0 2 | -------------------------------------------------------------------------------- /testdata/gawk/strtod.ok: -------------------------------------------------------------------------------- 1 | 0x345 0 2 | 345 is not zero 3 | -------------------------------------------------------------------------------- /testdata/gawk/subamp.awk: -------------------------------------------------------------------------------- 1 | { sub(/[[:lower:]]/, "&") ; print } 2 | -------------------------------------------------------------------------------- /testdata/gawk/subamp.in: -------------------------------------------------------------------------------- 1 | aaa 2 | -------------------------------------------------------------------------------- /testdata/gawk/subamp.ok: -------------------------------------------------------------------------------- 1 | aaa 2 | -------------------------------------------------------------------------------- /testdata/gawk/subback.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | A[0] = "&" 3 | for(i=1;i<=11;i++) { 4 | A[i] = "\\" A[i-1] 5 | } 6 | ## A[] holds & \& \\& \\\& \\\\& ... 7 | } 8 | 9 | { 10 | for(i=0; i <= 11 ; i++) { 11 | x = $0 12 | sub(/B/, A[i], x) 13 | print i, x 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /testdata/gawk/subback.in: -------------------------------------------------------------------------------- 1 | B 2 | -------------------------------------------------------------------------------- /testdata/gawk/subback.ok: -------------------------------------------------------------------------------- 1 | 0 B 2 | 1 & 3 | 2 \B 4 | 3 \& 5 | 4 \\B 6 | 5 \\& 7 | 6 \\\B 8 | 7 \\\& 9 | 8 \\\\B 10 | 9 \\\\& 11 | 10 \\\\\B 12 | 11 \\\\\& 13 | -------------------------------------------------------------------------------- /testdata/gawk/subi18n.ok: -------------------------------------------------------------------------------- 1 | "directory" version="1.0" 2 | "1.0" 3 | -------------------------------------------------------------------------------- /testdata/gawk/subsepnm.awk: -------------------------------------------------------------------------------- 1 | BEGIN { SUBSEP = 10; a[1, 1] = 100 ; print a[1 SUBSEP 1] } 2 | -------------------------------------------------------------------------------- /testdata/gawk/subsepnm.ok: -------------------------------------------------------------------------------- 1 | 100 2 | -------------------------------------------------------------------------------- /testdata/gawk/subslash.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | i = 2 3 | a[i] = 5 4 | a[i] /= 2 5 | printf "a[%s] = %f\n", i, a[i] 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/subslash.ok: -------------------------------------------------------------------------------- 1 | a[2] = 2.500000 2 | -------------------------------------------------------------------------------- /testdata/gawk/substr.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | x = "A" 3 | printf("%-39s\n", substr(x,1,39)) 4 | print substr("abcdef", 0, 2) 5 | print substr("abcdef", 2.3, 2) 6 | print substr("abcdef", -1, 2) 7 | print substr("abcdef", 1, 0) 8 | print substr("abcdef", 1, -3) 9 | print substr("abcdef", 1, 2.3) 10 | print substr("", 1, 2) 11 | print substr("abcdef", 5, 5) 12 | print substr("abcdef", 7, 2) 13 | exit (0) 14 | } 15 | -------------------------------------------------------------------------------- /testdata/gawk/substr.ok: -------------------------------------------------------------------------------- 1 | A 2 | ab 3 | bc 4 | ab 5 | 6 | 7 | ab 8 | 9 | ef 10 | 11 | -------------------------------------------------------------------------------- /testdata/gawk/swaplns.awk: -------------------------------------------------------------------------------- 1 | { 2 | if ((getline tmp) > 0) { 3 | print tmp 4 | print 5 | } else 6 | print 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/swaplns.in: -------------------------------------------------------------------------------- 1 | This directory contains some examples/test-cases for different 2 | features of gawk - mostly not present in an old awk. Some are from 3 | "The GAWK Manual", some are original, and some are mixture of the two. 4 | Read header comments before attempting to use. Have fun and remember 5 | that program which consists only of BEGIN block does not need an input 6 | file. 7 | 8 | --mj 9 | 10 | -------------------------------------------------------------------------------- /testdata/gawk/swaplns.ok: -------------------------------------------------------------------------------- 1 | features of gawk - mostly not present in an old awk. Some are from 2 | This directory contains some examples/test-cases for different 3 | Read header comments before attempting to use. Have fun and remember 4 | "The GAWK Manual", some are original, and some are mixture of the two. 5 | file. 6 | that program which consists only of BEGIN block does not need an input 7 | --mj 8 | 9 | 10 | -------------------------------------------------------------------------------- /testdata/gawk/synerr1.awk: -------------------------------------------------------------------------------- 1 | # program to make sure we don't infinite 2 | # syntax errors 3 | 4 | print "hi" 5 | -------------------------------------------------------------------------------- /testdata/gawk/synerr1.ok: -------------------------------------------------------------------------------- 1 | parse error at 4:1: expected expression instead of print -------------------------------------------------------------------------------- /testdata/gawk/synerr2.ok: -------------------------------------------------------------------------------- 1 | parse error at 47:24: expected expression instead of ) -------------------------------------------------------------------------------- /testdata/gawk/tailrecurse.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | abc(2) 3 | } 4 | 5 | 6 | function abc(c, A, B) 7 | { 8 | print "abc(" c ", " length(A) ")" 9 | if (! c--) { 10 | return 11 | } 12 | B[""] 13 | print length(B) 14 | return abc(c, B) 15 | } 16 | -------------------------------------------------------------------------------- /testdata/gawk/tailrecurse.ok: -------------------------------------------------------------------------------- 1 | abc(2, 0) 2 | 1 3 | abc(1, 1) 4 | 1 5 | abc(0, 1) 6 | -------------------------------------------------------------------------------- /testdata/gawk/tradanch.awk: -------------------------------------------------------------------------------- 1 | /foo^bar/ 2 | /foo$bar/ 3 | -------------------------------------------------------------------------------- /testdata/gawk/tradanch.in: -------------------------------------------------------------------------------- 1 | foo^bar 2 | foo$bar 3 | -------------------------------------------------------------------------------- /testdata/gawk/tradanch.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/tradanch.ok -------------------------------------------------------------------------------- /testdata/gawk/uninit2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { a = a + 1; x = a; print a} 2 | BEGIN { ++b; x = b; print b} 3 | -------------------------------------------------------------------------------- /testdata/gawk/uninit2.ok: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | -------------------------------------------------------------------------------- /testdata/gawk/uninit3.awk: -------------------------------------------------------------------------------- 1 | function f(x){ 2 | print x 3 | } 4 | 5 | BEGIN { 6 | f(x) 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/uninit3.ok: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testdata/gawk/uninit4.awk: -------------------------------------------------------------------------------- 1 | # test whether --lint catches uninitialized fields: 2 | function pr() 3 | { 4 | print 5 | } 6 | 7 | BEGIN { 8 | pr() 9 | print $0 10 | print $(1-1) 11 | print $1 12 | NF=3; print $2 13 | } 14 | -------------------------------------------------------------------------------- /testdata/gawk/uninit4.ok: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /testdata/gawk/uninit5.ok: -------------------------------------------------------------------------------- 1 | length: 0 2 | 3 | 4 | length: 0 5 | 6 | 7 | -------------------------------------------------------------------------------- /testdata/gawk/uninitialized.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | a += 2 3 | } 4 | -------------------------------------------------------------------------------- /testdata/gawk/uninitialized.ok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/gawk/uninitialized.ok -------------------------------------------------------------------------------- /testdata/gawk/unterm.awk: -------------------------------------------------------------------------------- 1 | BEGIN{x=".........................................................................................................................................................................................................................................................} -------------------------------------------------------------------------------- /testdata/gawk/unterm.ok: -------------------------------------------------------------------------------- 1 | parse error at 1:260: didn't find end quote in string -------------------------------------------------------------------------------- /testdata/gawk/uparrfs.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | FS = "(^x+)|( +)" 3 | } 4 | 5 | { 6 | for (i = 1; i <= NF; i++) 7 | printf "-->%s<--\n", $i 8 | } 9 | -------------------------------------------------------------------------------- /testdata/gawk/uparrfs.in: -------------------------------------------------------------------------------- 1 | xxAA xxBxx C 2 | -------------------------------------------------------------------------------- /testdata/gawk/uparrfs.ok: -------------------------------------------------------------------------------- 1 | --><-- 2 | -->AA<-- 3 | -->xxBxx<-- 4 | -->C<-- 5 | -------------------------------------------------------------------------------- /testdata/gawk/uplus.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | print "01" + 0 3 | print +"01" 4 | print -"01" 5 | } 6 | -------------------------------------------------------------------------------- /testdata/gawk/uplus.ok: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | -1 4 | -------------------------------------------------------------------------------- /testdata/gawk/wideidx.awk: -------------------------------------------------------------------------------- 1 | { 2 | a=$0 3 | print index(a,"b") 4 | getline 5 | a = a $0 6 | print index(a,"b") 7 | } 8 | -------------------------------------------------------------------------------- /testdata/gawk/wideidx.in: -------------------------------------------------------------------------------- 1 | foo 2 | bar 3 | -------------------------------------------------------------------------------- /testdata/gawk/wideidx.ok: -------------------------------------------------------------------------------- 1 | 0 2 | 4 3 | -------------------------------------------------------------------------------- /testdata/gawk/wideidx2.ok: -------------------------------------------------------------------------------- 1 | Before 2 2 | After 3 3 | -------------------------------------------------------------------------------- /testdata/gawk/widesub.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | str = "type=\"directory\" version=\"1.0\"" 3 | #print "BEGIN:", str 4 | 5 | while (str) { 6 | sub(/^[^=]*/, "", str); 7 | s = substr(str, 2) 8 | print s 9 | sub(/^="[^"]*"/, "", str) 10 | sub(/^[ \t]*/, "", str) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /testdata/gawk/widesub.ok: -------------------------------------------------------------------------------- 1 | "directory" version="1.0" 2 | "1.0" 3 | -------------------------------------------------------------------------------- /testdata/gawk/widesub2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | Value = "abc" 3 | 4 | print "Before <" Value "> ", index( Value, "bc" ) 5 | 6 | sub( /bc/, "bbc", Value ) 7 | 8 | print "After <" Value ">", index( Value, "bc" ) 9 | } 10 | -------------------------------------------------------------------------------- /testdata/gawk/widesub2.ok: -------------------------------------------------------------------------------- 1 | Before 2 2 | After 3 3 | -------------------------------------------------------------------------------- /testdata/gawk/widesub3.awk: -------------------------------------------------------------------------------- 1 | { 2 | if (substr($1,1,1) == substr($0,1,1)) 3 | print "substr matches" 4 | sub(/foo/,"bar") 5 | print nr++ 6 | } 7 | -------------------------------------------------------------------------------- /testdata/gawk/widesub3.in: -------------------------------------------------------------------------------- 1 | test 2 | foo 3 | -------------------------------------------------------------------------------- /testdata/gawk/widesub3.ok: -------------------------------------------------------------------------------- 1 | substr matches 2 | 0 3 | substr matches 4 | 1 5 | -------------------------------------------------------------------------------- /testdata/gawk/widesub4.ok: -------------------------------------------------------------------------------- 1 | 16 A=1234567890abcdef. 2 | 12 A=567890abcdef. 3 | 8 A=90abcdef. 4 | 4 A=cdef. 5 | 0 A=. 6 | -------------------------------------------------------------------------------- /testdata/gawk/zero2.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | printf "%d\n", -.4 3 | printf "%d\n", -0.0 4 | printf "%d\n", -.9 5 | } 6 | -------------------------------------------------------------------------------- /testdata/gawk/zero2.ok: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 0 4 | -------------------------------------------------------------------------------- /testdata/gawk/zeroe0.ok: -------------------------------------------------------------------------------- 1 | 00E0, 1, 1 2 | 00E0, 1, 1 3 | -------------------------------------------------------------------------------- /testdata/gawk/zeroflag.awk: -------------------------------------------------------------------------------- 1 | BEGIN { printf("%2.1d---%02.1d\n", 2, 2) } 2 | -------------------------------------------------------------------------------- /testdata/gawk/zeroflag.ok: -------------------------------------------------------------------------------- 1 | 2--- 2 2 | -------------------------------------------------------------------------------- /testdata/output/p.1: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | Canada 3852 24 North America 3 | China 3692 866 Asia 4 | USA 3615 219 North America 5 | Brazil 3286 116 South America 6 | Australia 2968 14 Australia 7 | India 1269 637 Asia 8 | Argentina 1072 26 South America 9 | Sudan 968 19 Africa 10 | Algeria 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/p.10: -------------------------------------------------------------------------------- 1 | Australia 2968 14 Australia 2 | -------------------------------------------------------------------------------- /testdata/output/p.11: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | China 3692 866 Asia 3 | India 1269 637 Asia 4 | -------------------------------------------------------------------------------- /testdata/output/p.12: -------------------------------------------------------------------------------- 1 | Russia 2 | China 3 | India 4 | -------------------------------------------------------------------------------- /testdata/output/p.13: -------------------------------------------------------------------------------- 1 | Canada 2 | USA 3 | Brazil 4 | Australia 5 | Argentina 6 | Sudan 7 | Algeria 8 | -------------------------------------------------------------------------------- /testdata/output/p.14: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.14 -------------------------------------------------------------------------------- /testdata/output/p.15: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.15 -------------------------------------------------------------------------------- /testdata/output/p.16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.16 -------------------------------------------------------------------------------- /testdata/output/p.17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.17 -------------------------------------------------------------------------------- /testdata/output/p.18: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.18 -------------------------------------------------------------------------------- /testdata/output/p.19: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.19 -------------------------------------------------------------------------------- /testdata/output/p.2: -------------------------------------------------------------------------------- 1 | Russia 262 2 | Canada 24 3 | China 866 4 | USA 219 5 | Brazil 116 6 | Australia 14 7 | India 637 8 | Argentina 26 9 | Sudan 19 10 | Algeria 18 11 | -------------------------------------------------------------------------------- /testdata/output/p.20: -------------------------------------------------------------------------------- 1 | China 3692 866 Asia 2 | India 1269 637 Asia 3 | -------------------------------------------------------------------------------- /testdata/output/p.21: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | China 3692 866 Asia 3 | India 1269 637 Asia 4 | -------------------------------------------------------------------------------- /testdata/output/p.21a: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | China 3692 866 Asia 3 | India 1269 637 Asia 4 | Sudan 968 19 Africa 5 | Algeria 920 18 Africa 6 | -------------------------------------------------------------------------------- /testdata/output/p.22: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | China 3692 866 Asia 3 | India 1269 637 Asia 4 | -------------------------------------------------------------------------------- /testdata/output/p.23: -------------------------------------------------------------------------------- 1 | Canada 3852 24 North America 2 | China 3692 866 Asia 3 | USA 3615 219 North America 4 | Brazil 3286 116 South America 5 | -------------------------------------------------------------------------------- /testdata/output/p.24: -------------------------------------------------------------------------------- 1 | testdata/test.countries Russia 8650 262 Asia 2 | testdata/test.countries Canada 3852 24 North America 3 | testdata/test.countries China 3692 866 Asia 4 | testdata/test.countries USA 3615 219 North America 5 | testdata/test.countries Brazil 3286 116 South America 6 | -------------------------------------------------------------------------------- /testdata/output/p.25: -------------------------------------------------------------------------------- 1 | Russia 30.3 2 | Canada 6.2 3 | China 234.6 4 | USA 60.6 5 | Brazil 35.3 6 | Australia 4.7 7 | India 502.0 8 | Argentina 24.3 9 | Sudan 19.6 10 | Algeria 19.6 11 | -------------------------------------------------------------------------------- /testdata/output/p.26: -------------------------------------------------------------------------------- 1 | population of 3 Asian countries in millions is 1765 2 | -------------------------------------------------------------------------------- /testdata/output/p.26a: -------------------------------------------------------------------------------- 1 | population of 3 Asian countries in millions is 1765 2 | -------------------------------------------------------------------------------- /testdata/output/p.27: -------------------------------------------------------------------------------- 1 | China 866 2 | -------------------------------------------------------------------------------- /testdata/output/p.28: -------------------------------------------------------------------------------- 1 | 1:Russia 8650 262 Asia 2 | 2:Canada 3852 24 North America 3 | 3:China 3692 866 Asia 4 | 4:USA 3615 219 North America 5 | 5:Brazil 3286 116 South America 6 | 6:Australia 2968 14 Australia 7 | 7:India 1269 637 Asia 8 | 8:Argentina 1072 26 South America 9 | 9:Sudan 968 19 Africa 10 | 10:Algeria 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/p.29: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | Canada 3852 24 North America 3 | China 3692 866 Asia 4 | United States 3615 219 North America 5 | Brazil 3286 116 South America 6 | Australia 2968 14 Australia 7 | India 1269 637 Asia 8 | Argentina 1072 26 South America 9 | Sudan 968 19 Africa 10 | Algeria 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/p.3: -------------------------------------------------------------------------------- 1 | [ Russia] [262 ] 2 | [ Canada] [24 ] 3 | [ China] [866 ] 4 | [ USA] [219 ] 5 | [ Brazil] [116 ] 6 | [ Australia] [14 ] 7 | [ India] [637 ] 8 | [ Argentina] [26 ] 9 | [ Sudan] [19 ] 10 | [ Algeria] [18 ] 11 | -------------------------------------------------------------------------------- /testdata/output/p.30: -------------------------------------------------------------------------------- 1 | 20 Russia 8650 262 Asia 2 | 28 Canada 3852 24 North America 3 | 19 China 3692 866 Asia 4 | 26 USA 3615 219 North America 5 | 29 Brazil 3286 116 South America 6 | 27 Australia 2968 14 Australia 7 | 19 India 1269 637 Asia 8 | 31 Argentina 1072 26 South America 9 | 19 Sudan 968 19 Africa 10 | 21 Algeria 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/p.31: -------------------------------------------------------------------------------- 1 | Australia 2 | -------------------------------------------------------------------------------- /testdata/output/p.32: -------------------------------------------------------------------------------- 1 | Rus 8650 262 Asia 2 | Can 3852 24 North America 3 | Chi 3692 866 Asia 4 | USA 3615 219 North America 5 | Bra 3286 116 South America 6 | Aus 2968 14 Australia 7 | Ind 1269 637 Asia 8 | Arg 1072 26 South America 9 | Sud 968 19 Africa 10 | Alg 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/p.33: -------------------------------------------------------------------------------- 1 | Rus Can Chi USA Bra Aus Ind Arg Sud Alg 2 | -------------------------------------------------------------------------------- /testdata/output/p.34: -------------------------------------------------------------------------------- 1 | Russia 8.65 262 Asia 2 | Canada 3.852 24 North America 3 | China 3.692 866 Asia 4 | USA 3.615 219 North America 5 | Brazil 3.286 116 South America 6 | Australia 2.968 14 Australia 7 | India 1.269 637 Asia 8 | Argentina 1.072 26 South America 9 | Sudan 0.968 19 Africa 10 | Algeria 0.92 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/p.35: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | Canada 3852 24 NA 3 | China 3692 866 Asia 4 | USA 3615 219 NA 5 | Brazil 3286 116 SA 6 | Australia 2968 14 Australia 7 | India 1269 637 Asia 8 | Argentina 1072 26 SA 9 | Sudan 968 19 Africa 10 | Algeria 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/p.36: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 30.289 2 | Canada 3852 24 North America 6.23053 3 | China 3692 866 Asia 234.561 4 | USA 3615 219 North America 60.5809 5 | Brazil 3286 116 South America 35.3013 6 | Australia 2968 14 Australia 4.71698 7 | India 1269 637 Asia 501.97 8 | Argentina 1072 26 South America 24.2537 9 | Sudan 968 19 Africa 19.6281 10 | Algeria 920 18 Africa 19.5652 11 | -------------------------------------------------------------------------------- /testdata/output/p.37: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.37 -------------------------------------------------------------------------------- /testdata/output/p.38: -------------------------------------------------------------------------------- 1 | China 866 2 | -------------------------------------------------------------------------------- /testdata/output/p.39: -------------------------------------------------------------------------------- 1 | Russia 2 | 8650 3 | 262 4 | Asia 5 | Canada 6 | 3852 7 | 24 8 | North 9 | America 10 | China 11 | 3692 12 | 866 13 | Asia 14 | USA 15 | 3615 16 | 219 17 | North 18 | America 19 | Brazil 20 | 3286 21 | 116 22 | South 23 | America 24 | Australia 25 | 2968 26 | 14 27 | Australia 28 | India 29 | 1269 30 | 637 31 | Asia 32 | Argentina 33 | 1072 34 | 26 35 | South 36 | America 37 | Sudan 38 | 968 39 | 19 40 | Africa 41 | Algeria 42 | 920 43 | 18 44 | Africa 45 | -------------------------------------------------------------------------------- /testdata/output/p.4: -------------------------------------------------------------------------------- 1 | 1 Russia 8650 262 Asia 2 | 2 Canada 3852 24 North America 3 | 3 China 3692 866 Asia 4 | 4 USA 3615 219 North America 5 | 5 Brazil 3286 116 South America 6 | 6 Australia 2968 14 Australia 7 | 7 India 1269 637 Asia 8 | 8 Argentina 1072 26 South America 9 | 9 Sudan 968 19 Africa 10 | 10 Algeria 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/p.40: -------------------------------------------------------------------------------- 1 | Russia 2 | 8650 3 | 262 4 | Asia 5 | Canada 6 | 3852 7 | 24 8 | North 9 | America 10 | China 11 | 3692 12 | 866 13 | Asia 14 | USA 15 | 3615 16 | 219 17 | North 18 | America 19 | Brazil 20 | 3286 21 | 116 22 | South 23 | America 24 | Australia 25 | 2968 26 | 14 27 | Australia 28 | India 29 | 1269 30 | 637 31 | Asia 32 | Argentina 33 | 1072 34 | 26 35 | South 36 | America 37 | Sudan 38 | 968 39 | 19 40 | Africa 41 | Algeria 42 | 920 43 | 18 44 | Africa 45 | -------------------------------------------------------------------------------- /testdata/output/p.41: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.41 -------------------------------------------------------------------------------- /testdata/output/p.42: -------------------------------------------------------------------------------- 1 | Asian population in millions is 1765 2 | African population in millions is 37 3 | -------------------------------------------------------------------------------- /testdata/output/p.43: -------------------------------------------------------------------------------- 1 | Africa:1888 2 | Asia:13611 3 | Australia:2968 4 | North America:7467 5 | South America:4358 6 | -------------------------------------------------------------------------------- /testdata/output/p.44: -------------------------------------------------------------------------------- 1 | Russia! is 0 2 | Canada! is 0 3 | China! is 0 4 | USA! is 0 5 | Brazil! is 0 6 | Australia! is 0 7 | India! is 0 8 | Argentina! is 0 9 | Sudan! is 0 10 | Algeria! is 0 11 | -------------------------------------------------------------------------------- /testdata/output/p.45: -------------------------------------------------------------------------------- 1 | Russia:8650 2 | 3 | Canada:3852 4 | 5 | China:3692 6 | 7 | USA:3615 8 | 9 | Brazil:3286 10 | 11 | Australia:2968 12 | 13 | India:1269 14 | 15 | Argentina:1072 16 | 17 | Sudan:968 18 | 19 | Algeria:920 20 | 21 | -------------------------------------------------------------------------------- /testdata/output/p.46: -------------------------------------------------------------------------------- 1 | Russia8650 2 | Canada3852 3 | China3692 4 | USA3615 5 | Brazil3286 6 | Australia2968 7 | India1269 8 | Argentina1072 9 | Sudan968 10 | Algeria920 11 | -------------------------------------------------------------------------------- /testdata/output/p.47: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.47 -------------------------------------------------------------------------------- /testdata/output/p.48: -------------------------------------------------------------------------------- 1 | Africa:37 2 | Asia:1765 3 | Australia:14 4 | North America:243 5 | South America:142 6 | -------------------------------------------------------------------------------- /testdata/output/p.48a: -------------------------------------------------------------------------------- 1 | testdata/test.countries 2 | -------------------------------------------------------------------------------- /testdata/output/p.48b: -------------------------------------------------------------------------------- 1 | China 3692 866 Asia 2 | India 1269 637 Asia 3 | Argentina 1072 26 South America 4 | -------------------------------------------------------------------------------- /testdata/output/p.49: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/p.49 -------------------------------------------------------------------------------- /testdata/output/p.5: -------------------------------------------------------------------------------- 1 | COUNTRY AREA POP CONTINENT 2 | Russia 8650 262 Asia 3 | Canada 3852 24 North America 4 | China 3692 866 Asia 5 | USA 3615 219 North America 6 | Brazil 3286 116 South America 7 | Australia 2968 14 Australia 8 | India 1269 637 Asia 9 | Argentina 1072 26 South America 10 | Sudan 968 19 Africa 11 | Algeria 920 18 Africa 12 | -------------------------------------------------------------------------------- /testdata/output/p.50: -------------------------------------------------------------------------------- 1 | Africa:Sudan:19 2 | Africa:Algeria:18 3 | Asia:China:866 4 | Asia:India:637 5 | Asia:Russia:262 6 | Australia:Australia:14 7 | North America:USA:219 8 | North America:Canada:24 9 | South America:Brazil:116 10 | South America:Argentina:26 11 | -------------------------------------------------------------------------------- /testdata/output/p.5a: -------------------------------------------------------------------------------- 1 | COUNTRY AREA POP'N CONTINENT 2 | Russia 8650 262 Asia 3 | Canada 3852 24 North America 4 | China 3692 866 Asia 5 | USA 3615 219 North America 6 | Brazil 3286 116 South America 7 | Australia 2968 14 Australia 8 | India 1269 637 Asia 9 | Argentina 1072 26 South America 10 | Sudan 968 19 Africa 11 | Algeria 920 18 Africa 12 | -------------------------------------------------------------------------------- /testdata/output/p.6: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testdata/output/p.7: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | China 3692 866 Asia 3 | USA 3615 219 North America 4 | Brazil 3286 116 South America 5 | India 1269 637 Asia 6 | -------------------------------------------------------------------------------- /testdata/output/p.8: -------------------------------------------------------------------------------- 1 | Russia 2 | China 3 | India 4 | -------------------------------------------------------------------------------- /testdata/output/p.9: -------------------------------------------------------------------------------- 1 | USA 3615 219 North America 2 | Sudan 968 19 Africa 3 | -------------------------------------------------------------------------------- /testdata/output/p.table: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | Canada 3852 24 North America 3 | China 3692 866 Asia 4 | USA 3615 219 North America 5 | Brazil 3286 116 South America 6 | Australia 2968 14 Australia 7 | India 1269 637 Asia 8 | Argentina 1072 26 South America 9 | Sudan 968 19 Africa 10 | Algeria 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/output/t.3: -------------------------------------------------------------------------------- 1 | 5 evp 2 | 4 ber 3 | 4 men 4 | 4 mitch 5 | -------------------------------------------------------------------------------- /testdata/output/t.addops: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.addops -------------------------------------------------------------------------------- /testdata/output/t.aeiou: -------------------------------------------------------------------------------- 1 | 7360 ava 2 | 5671 dave 3 | 700 honey 4 | 348 ravi 5 | 224 sharon 6 | 123 dale 7 | 1 gopi 8 | 1 sidor 9 | -------------------------------------------------------------------------------- /testdata/output/t.aeiouy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.aeiouy -------------------------------------------------------------------------------- /testdata/output/t.array2: -------------------------------------------------------------------------------- 1 | 199 99 72 28 2 | -------------------------------------------------------------------------------- /testdata/output/t.avg: -------------------------------------------------------------------------------- 1 | sum= 341504 count= 199 2 | avg= 1716.1 3 | -------------------------------------------------------------------------------- /testdata/output/t.be: -------------------------------------------------------------------------------- 1 | 2 | 199 3 | -------------------------------------------------------------------------------- /testdata/output/t.beginexit: -------------------------------------------------------------------------------- 1 | /dev/rrp3: 2 | 3 | 17379 mel 4 | 16693 bwk me 5 | 16116 ken him someone else 6 | 15713 srb 7 | 11895 lem 8 | 10409 scj 9 | 10252 rhm 10 | 9853 shen 11 | -------------------------------------------------------------------------------- /testdata/output/t.break1: -------------------------------------------------------------------------------- 1 | 1 /dev/rrp3: 2 | 2 3 | 3 17379 mel 4 | 4 16693 bwk me 5 | 5 16116 ken him someone else 6 | 6 15713 srb 7 | 7 11895 lem 8 | 8 10409 scj 9 | 9 10252 rhm 10 | 10 9853 shen 11 | got here 12 | 10 9853 shen 13 | -------------------------------------------------------------------------------- /testdata/output/t.break2: -------------------------------------------------------------------------------- 1 | 1 /dev/rrp3: 2 | 2 3 | 3 17379 mel 4 | 4 16693 bwk me 5 | 5 16116 ken him someone else 6 | 6 15713 srb 7 | 7 11895 lem 8 | 8 10409 scj 9 | 9 10252 rhm 10 | 10 9853 shen 11 | got here 12 | 10 9853 shen 13 | -------------------------------------------------------------------------------- /testdata/output/t.coerce: -------------------------------------------------------------------------------- 1 | 199 2 | 199 3 | -------------------------------------------------------------------------------- /testdata/output/t.comment: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.comment -------------------------------------------------------------------------------- /testdata/output/t.comment1: -------------------------------------------------------------------------------- 1 | 199 2 | -------------------------------------------------------------------------------- /testdata/output/t.count: -------------------------------------------------------------------------------- 1 | 199 2 | -------------------------------------------------------------------------------- /testdata/output/t.delete1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.delete1 -------------------------------------------------------------------------------- /testdata/output/t.delete3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.delete3 -------------------------------------------------------------------------------- /testdata/output/t.do: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.do -------------------------------------------------------------------------------- /testdata/output/t.e: -------------------------------------------------------------------------------- 1 | /dev/rrp3: 2 | 3 | 16693 bwk me 4 | 6 aed 5 | 6 cpb 6 | 5 evp 7 | 4 ber 8 | 4 men 9 | 4 mitch 10 | 3 ast 11 | 3 jfr 12 | 3 lax 13 | 3 nel 14 | 2 blue 15 | 2 jfk 16 | 2 njas 17 | 1 122sec 18 | 1 ddwar 19 | 1 gopi 20 | 1 jk 21 | 1 learn 22 | 1 low 23 | 1 nac 24 | 1 sidor 25 | -------------------------------------------------------------------------------- /testdata/output/t.exit: -------------------------------------------------------------------------------- 1 | /dev/rrp3: 2 | -------------------------------------------------------------------------------- /testdata/output/t.exit1: -------------------------------------------------------------------------------- 1 | this is before calling myabort 2 | in myabort - before exit 1 3 | into END 4 | in myabort - before exit 2 5 | -------------------------------------------------------------------------------- /testdata/output/t.f0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.f0 -------------------------------------------------------------------------------- /testdata/output/t.format4: -------------------------------------------------------------------------------- 1 | 125 2 | x 3 | 105 4 | 5 | -------------------------------------------------------------------------------- /testdata/output/t.fun1: -------------------------------------------------------------------------------- 1 | hello 2 | hello 3 | -------------------------------------------------------------------------------- /testdata/output/t.in: -------------------------------------------------------------------------------- 1 | apple 1 2 | lemon 3 3 | orange 2 4 | -------------------------------------------------------------------------------- /testdata/output/t.in2: -------------------------------------------------------------------------------- 1 | 21 2 | 1 1 3 | 4 22 4 | A 266 5 | D 33 6 | E 17 7 | F 10 8 | K 29 9 | M 29 10 | O 26 11 | S 48 12 | T 6 13 | U 37 14 | V 3 15 | a 24857 16 | b 38345 17 | c 11648 18 | d 29727 19 | e 3158 20 | f 143 21 | g 9084 22 | h 958 23 | i 10 24 | j 24382 25 | k 16744 26 | l 34040 27 | m 33545 28 | n 9062 29 | o 3 30 | p 13563 31 | r 21272 32 | s 51795 33 | t 8559 34 | u 1454 35 | v 5050 36 | w 64 37 | x 3481 38 | y 12 39 | -------------------------------------------------------------------------------- /testdata/output/t.in3: -------------------------------------------------------------------------------- 1 | 10 9853 shen 2 | -------------------------------------------------------------------------------- /testdata/output/t.incr: -------------------------------------------------------------------------------- 1 | 199 199 -199 199 -199 2 | -------------------------------------------------------------------------------- /testdata/output/t.longstr: -------------------------------------------------------------------------------- 1 | 111111111122222222233333333334444444444555555555566666666667777777777888888888899999999990000000000 2 | -------------------------------------------------------------------------------- /testdata/output/t.match: -------------------------------------------------------------------------------- 1 | 16693 bwk me 2 | 7360 ava 3 | -------------------------------------------------------------------------------- /testdata/output/t.match1: -------------------------------------------------------------------------------- 1 | /dev/rrp3: 1 10 2 | 1 122sec 1 1 3 | 1root:EMpNB8Zp56:0:0:Super-User,,,,,,,:/:/bin/sh 1 48 4 | 7nuucp:BJnuQbAo:6:10:UUCP.Admin:/usr/spool/uucppublic:/usr/lib/uucp/uucico 1 74 5 | -------------------------------------------------------------------------------- /testdata/output/t.max: -------------------------------------------------------------------------------- 1 | 75 7n uucp BJnuQbAo 6 10 UUCP.Admin /usr/spool/uucppublic /usr/lib/uucp/uucico 2 | -------------------------------------------------------------------------------- /testdata/output/t.monotone: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testdata/output/t.pipe: -------------------------------------------------------------------------------- 1 | read /usr/bwk/awk/t.pipe 2 | -------------------------------------------------------------------------------- /testdata/output/t.pp1: -------------------------------------------------------------------------------- 1 | bwk 16693 2 | pjw 9190 3 | ava 7360 4 | -------------------------------------------------------------------------------- /testdata/output/t.printf2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.printf2 -------------------------------------------------------------------------------- /testdata/output/t.re7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.re7 -------------------------------------------------------------------------------- /testdata/output/t.split2a: -------------------------------------------------------------------------------- 1 | 2 a b 2 | -------------------------------------------------------------------------------- /testdata/output/t.split9: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.split9 -------------------------------------------------------------------------------- /testdata/output/t.split9a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhoyt/goawk/4b6c79a6da06fc8e53eeb25c96f3b0e89d53c818/testdata/output/t.split9a -------------------------------------------------------------------------------- /testdata/output/t.stately: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testdata/output/t.strnum: -------------------------------------------------------------------------------- 1 | 100 0.12 1.23457 2 | -------------------------------------------------------------------------------- /testdata/output/t.x: -------------------------------------------------------------------------------- 1 | 3481 xchar 2 | 143 fox 3 | 3 lax 4 | -------------------------------------------------------------------------------- /testdata/p.1: -------------------------------------------------------------------------------- 1 | { print } 2 | -------------------------------------------------------------------------------- /testdata/p.10: -------------------------------------------------------------------------------- 1 | $1 == $4 2 | -------------------------------------------------------------------------------- /testdata/p.11: -------------------------------------------------------------------------------- 1 | /Asia/ 2 | -------------------------------------------------------------------------------- /testdata/p.12: -------------------------------------------------------------------------------- 1 | $4 ~ /Asia/ { print $1 } 2 | -------------------------------------------------------------------------------- /testdata/p.13: -------------------------------------------------------------------------------- 1 | $4 !~ /Asia/ {print $1 } 2 | -------------------------------------------------------------------------------- /testdata/p.14: -------------------------------------------------------------------------------- 1 | /\$/ 2 | -------------------------------------------------------------------------------- /testdata/p.15: -------------------------------------------------------------------------------- 1 | /\\/ 2 | -------------------------------------------------------------------------------- /testdata/p.16: -------------------------------------------------------------------------------- 1 | /^.$/ 2 | -------------------------------------------------------------------------------- /testdata/p.17: -------------------------------------------------------------------------------- 1 | $2 !~ /^[0-9]+$/ 2 | -------------------------------------------------------------------------------- /testdata/p.18: -------------------------------------------------------------------------------- 1 | /(apple|cherry) (pie|tart)/ 2 | -------------------------------------------------------------------------------- /testdata/p.19: -------------------------------------------------------------------------------- 1 | BEGIN { digits = "^[0-9]+$" } 2 | $2 !~ digits 3 | -------------------------------------------------------------------------------- /testdata/p.2: -------------------------------------------------------------------------------- 1 | { print $1, $3 } 2 | -------------------------------------------------------------------------------- /testdata/p.20: -------------------------------------------------------------------------------- 1 | $4 == "Asia" && $3 > 500 2 | -------------------------------------------------------------------------------- /testdata/p.21: -------------------------------------------------------------------------------- 1 | $4 == "Asia" || $4 == "Europe" 2 | -------------------------------------------------------------------------------- /testdata/p.21a: -------------------------------------------------------------------------------- 1 | /Asia/ || /Africa/ 2 | -------------------------------------------------------------------------------- /testdata/p.22: -------------------------------------------------------------------------------- 1 | $4 ~ /^(Asia|Europe)$/ 2 | -------------------------------------------------------------------------------- /testdata/p.23: -------------------------------------------------------------------------------- 1 | /Canada/, /Brazil/ 2 | -------------------------------------------------------------------------------- /testdata/p.24: -------------------------------------------------------------------------------- 1 | FNR == 1, FNR == 5 { print FILENAME, $0 } 2 | -------------------------------------------------------------------------------- /testdata/p.25: -------------------------------------------------------------------------------- 1 | { printf "%10s %6.1f\n", $1, 1000 * $3 / $2 } 2 | -------------------------------------------------------------------------------- /testdata/p.26: -------------------------------------------------------------------------------- 1 | /Asia/ { pop = pop + $3; n = n + 1 } 2 | END { print "population of", n,\ 3 | "Asian countries in millions is", pop } 4 | -------------------------------------------------------------------------------- /testdata/p.26a: -------------------------------------------------------------------------------- 1 | /Asia/ { pop += $3; ++n } 2 | END { print "population of", n,\ 3 | "Asian countries in millions is", pop } 4 | -------------------------------------------------------------------------------- /testdata/p.27: -------------------------------------------------------------------------------- 1 | maxpop < $3 { maxpop = $3; country = $1 } 2 | END { print country, maxpop } 3 | -------------------------------------------------------------------------------- /testdata/p.28: -------------------------------------------------------------------------------- 1 | { print NR ":" $0 } 2 | -------------------------------------------------------------------------------- /testdata/p.29: -------------------------------------------------------------------------------- 1 | { gsub(/USA/, "United States"); print } 2 | -------------------------------------------------------------------------------- /testdata/p.3: -------------------------------------------------------------------------------- 1 | { printf "[%10s] [%-16d]\n", $1, $3 } 2 | -------------------------------------------------------------------------------- /testdata/p.30: -------------------------------------------------------------------------------- 1 | { print length, $0 } 2 | -------------------------------------------------------------------------------- /testdata/p.31: -------------------------------------------------------------------------------- 1 | length($1) > max { max = length($1); name = $1 } 2 | END { print name } 3 | -------------------------------------------------------------------------------- /testdata/p.32: -------------------------------------------------------------------------------- 1 | { $1 = substr($1, 1, 3); print } 2 | -------------------------------------------------------------------------------- /testdata/p.33: -------------------------------------------------------------------------------- 1 | { s = s " " substr($1, 1, 3) } 2 | END { print s } 3 | -------------------------------------------------------------------------------- /testdata/p.34: -------------------------------------------------------------------------------- 1 | { $2 /= 1000; print } 2 | -------------------------------------------------------------------------------- /testdata/p.35: -------------------------------------------------------------------------------- 1 | BEGIN { FS = OFS = "\t" } 2 | $4 ~ /^North America$/ { $4 = "NA" } 3 | $4 ~ /^South America$/ { $4 = "SA" } 4 | { print } 5 | -------------------------------------------------------------------------------- /testdata/p.36: -------------------------------------------------------------------------------- 1 | BEGIN { FS = OFS = "\t" } 2 | { $5 = 1000 * $3 / $2 ; print $1, $2, $3, $4, $5 } 3 | -------------------------------------------------------------------------------- /testdata/p.37: -------------------------------------------------------------------------------- 1 | $1 "" == $2 "" 2 | -------------------------------------------------------------------------------- /testdata/p.38: -------------------------------------------------------------------------------- 1 | { if (maxpop < $3) { 2 | maxpop = $3 3 | country = $1 4 | } 5 | } 6 | END { print country, maxpop } 7 | -------------------------------------------------------------------------------- /testdata/p.39: -------------------------------------------------------------------------------- 1 | { i = 1 2 | while (i <= NF) { 3 | print $i 4 | i++ 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /testdata/p.4: -------------------------------------------------------------------------------- 1 | { print NR, $0 } 2 | -------------------------------------------------------------------------------- /testdata/p.40: -------------------------------------------------------------------------------- 1 | { for (i = 1; i <= NF; i++) 2 | print $i 3 | } 4 | -------------------------------------------------------------------------------- /testdata/p.41: -------------------------------------------------------------------------------- 1 | NR >= 10 { exit } 2 | END { if (NR < 10) 3 | print FILENAME " has only " NR " lines" } 4 | -------------------------------------------------------------------------------- /testdata/p.42: -------------------------------------------------------------------------------- 1 | /Asia/ { pop["Asia"] += $3 } 2 | /Africa/ { pop["Africa"] += $3 } 3 | END { print "Asian population in millions is", pop["Asia"] 4 | print "African population in millions is", pop["Africa"] } 5 | -------------------------------------------------------------------------------- /testdata/p.43: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\t" } 2 | { area[$4] += $2 } 3 | END { for (name in area) 4 | print name ":" area[name] } 5 | -------------------------------------------------------------------------------- /testdata/p.44: -------------------------------------------------------------------------------- 1 | function fact(n) { 2 | if (n <= 1) 3 | return 1 4 | else 5 | return n * fact(n-1) 6 | } 7 | { print $1 "! is " fact($1) } 8 | -------------------------------------------------------------------------------- /testdata/p.45: -------------------------------------------------------------------------------- 1 | BEGIN { OFS = ":" ; ORS = "\n\n" } 2 | { print $1, $2 } 3 | -------------------------------------------------------------------------------- /testdata/p.46: -------------------------------------------------------------------------------- 1 | { print $1 $2 } 2 | -------------------------------------------------------------------------------- /testdata/p.47: -------------------------------------------------------------------------------- 1 | $3 > 100 { print >"tempbig" } 2 | $3 <= 100 { print >"tempsmall" } 3 | -------------------------------------------------------------------------------- /testdata/p.48: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\t" } 2 | { pop[$4] += $3 } 3 | END { for (c in pop) 4 | print c ":" pop[c] | "sort" } 5 | -------------------------------------------------------------------------------- /testdata/p.48a: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | for (i = 1; i < ARGC; i++) 3 | printf "%s ", ARGV[i] 4 | printf "\n" 5 | exit 6 | } 7 | -------------------------------------------------------------------------------- /testdata/p.48b: -------------------------------------------------------------------------------- 1 | BEGIN { k = 3; n = 10 } 2 | { if (n <= 0) exit 3 | if (rand() <= k/n) { print; k-- } 4 | n-- 5 | } 6 | -------------------------------------------------------------------------------- /testdata/p.49: -------------------------------------------------------------------------------- 1 | $1 == "include" { system("cat " $2) } 2 | -------------------------------------------------------------------------------- /testdata/p.5: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\t" 2 | printf "%10s %6s %5s %15s\n", "COUNTRY", "AREA", "POP", "CONTINENT" } 3 | { printf "%10s %6d %5d %15s\n", $1, $2, $3, $4 } 4 | -------------------------------------------------------------------------------- /testdata/p.50: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\t" } 2 | { pop[$4 ":" $1] += $3 } 3 | END { for (cc in pop) 4 | print cc ":" pop[cc] | "sort -t: +0 -1 +2nr" } 5 | -------------------------------------------------------------------------------- /testdata/p.51: -------------------------------------------------------------------------------- 1 | BEGIN { FS = ":" } 2 | { if ($1 != prev) { 3 | print "\n" $1 ":" 4 | prev = $1 5 | } 6 | printf "\t%-10s %6d\n", $2, $3 7 | } 8 | -------------------------------------------------------------------------------- /testdata/p.52: -------------------------------------------------------------------------------- 1 | BEGIN { FS = ":" } 2 | { 3 | if ($1 != prev) { 4 | if (prev) { 5 | printf "\t%-10s\t %6d\n", "total", subtotal 6 | subtotal = 0 7 | } 8 | print "\n" $1 ":" 9 | prev = $1 10 | } 11 | printf "\t%-10s %6d\n", $2, $3 12 | wtotal += $3 13 | subtotal += $3 14 | } 15 | END { printf "\t%-10s\t %6d\n", "total", subtotal 16 | printf "\n%-10s\t\t %6d\n", "World Total", wtotal } 17 | -------------------------------------------------------------------------------- /testdata/p.5a: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\t" 2 | printf "%10s\t%6s\t%6s\t%15s\n", "COUNTRY", "AREA", "POP'N", "CONTINENT"} 3 | { printf "%10s\t%6d\t%6d\t%15s\n", $1, $2, $3, $4} 4 | -------------------------------------------------------------------------------- /testdata/p.6: -------------------------------------------------------------------------------- 1 | END { print NR } 2 | -------------------------------------------------------------------------------- /testdata/p.7: -------------------------------------------------------------------------------- 1 | $3 > 100 2 | -------------------------------------------------------------------------------- /testdata/p.8: -------------------------------------------------------------------------------- 1 | $4 == "Asia" { print $1 } 2 | -------------------------------------------------------------------------------- /testdata/p.9: -------------------------------------------------------------------------------- 1 | $1 >= "S" 2 | -------------------------------------------------------------------------------- /testdata/parseerror/bad.awk: -------------------------------------------------------------------------------- 1 | 2 | x* 3 | -------------------------------------------------------------------------------- /testdata/parseerror/good.awk: -------------------------------------------------------------------------------- 1 | { 2 | print $1 3 | } -------------------------------------------------------------------------------- /testdata/t.0: -------------------------------------------------------------------------------- 1 | { print } 2 | -------------------------------------------------------------------------------- /testdata/t.0a: -------------------------------------------------------------------------------- 1 | {i = i+1; print i, NR} 2 | -------------------------------------------------------------------------------- /testdata/t.1: -------------------------------------------------------------------------------- 1 | BEGIN {FS=":"} 2 | {print $1, $2, $3} 3 | -------------------------------------------------------------------------------- /testdata/t.1.x: -------------------------------------------------------------------------------- 1 | {i="count" $1 $2; print i , $0} 2 | -------------------------------------------------------------------------------- /testdata/t.2: -------------------------------------------------------------------------------- 1 | BEGIN {OFS="==="} 2 | {print $1, $2, $3} 3 | -------------------------------------------------------------------------------- /testdata/t.2.x: -------------------------------------------------------------------------------- 1 | {i=2; j=$3; $1=i;print i,j,$1} 2 | -------------------------------------------------------------------------------- /testdata/t.3: -------------------------------------------------------------------------------- 1 | $1 == "5" || $1 == "4" 2 | -------------------------------------------------------------------------------- /testdata/t.3.x: -------------------------------------------------------------------------------- 1 | { 2 | x = $1 3 | while (x > 1) { 4 | print x 5 | x = x / 10 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.4: -------------------------------------------------------------------------------- 1 | $1 ~ /5/ || $1 ~ /4/ 2 | -------------------------------------------------------------------------------- /testdata/t.4.x: -------------------------------------------------------------------------------- 1 | {i=$(1); print i} 2 | -------------------------------------------------------------------------------- /testdata/t.5.x: -------------------------------------------------------------------------------- 1 | {$(1) = "xxx"; print $1,$0} 2 | -------------------------------------------------------------------------------- /testdata/t.6: -------------------------------------------------------------------------------- 1 | /a|b|c/ { 2 | i = $1 3 | print 4 | while (i >= 1) { 5 | print " ", i 6 | i = i / 10 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /testdata/t.6.x: -------------------------------------------------------------------------------- 1 | {print NF,$0} 2 | -------------------------------------------------------------------------------- /testdata/t.6a: -------------------------------------------------------------------------------- 1 | /a|b|c/ { 2 | print 3 | for (i = $1; i >= 1; ) 4 | print " ", i /= 10 5 | } 6 | -------------------------------------------------------------------------------- /testdata/t.6b: -------------------------------------------------------------------------------- 1 | /a|b|c/ { 2 | print 3 | for (i = $1; (i /= 10)>= 1; ) 4 | print " ", i 5 | } 6 | -------------------------------------------------------------------------------- /testdata/t.8.x: -------------------------------------------------------------------------------- 1 | {$2=$1; print} 2 | 3 | # this should produce a blank for an empty input line 4 | # since it has created fields 1 and 2. 5 | -------------------------------------------------------------------------------- /testdata/t.8.y: -------------------------------------------------------------------------------- 1 | {$1=$2; print} 2 | 3 | # this should print nothing for an empty input line 4 | # since it has only referred to $2, not created it, 5 | # and thus only $1 exists (and it's null). 6 | 7 | # is this right??? 8 | -------------------------------------------------------------------------------- /testdata/t.NF: -------------------------------------------------------------------------------- 1 | { OFS = "|"; print NF; NF = 2; print NF; print; $5 = "five"; print NF; print } 2 | -------------------------------------------------------------------------------- /testdata/t.a: -------------------------------------------------------------------------------- 1 | {if (amount[$2] "" == "") item[++num] = $2; 2 | amount[$2] += $1 3 | } 4 | END {for (i=1; i<=num; i++) 5 | print item[i], amount[item[i]] 6 | } 7 | -------------------------------------------------------------------------------- /testdata/t.aeiou: -------------------------------------------------------------------------------- 1 | /^[^aeiouy]*[aeiou][^aeiouy][aeiouy][aeiouy]*[^aeiouy]*$/ 2 | -------------------------------------------------------------------------------- /testdata/t.aeiouy: -------------------------------------------------------------------------------- 1 | /^[^aeiouy]*a[^aeiouy]*e[^aeiouy]*i[^aeiouy]*o[^aeiouy]*u[^aeiouy]*y[^aeiouy]*$/ 2 | -------------------------------------------------------------------------------- /testdata/t.arith: -------------------------------------------------------------------------------- 1 | { print NR, $1, $1+$1, $1-$1, $1 * $1 } 2 | { print NR, $1/NR, $1 % NR } 3 | # { print NR, $1++, $1--, --$1, $1-- } # this depends on order of eval of args! 4 | { print NR, -$1 } 5 | $1 > 0 { print NR, $1 ^ 0.5 } 6 | $1 > 0 { print NR, $1 ** 0.5 } 7 | -------------------------------------------------------------------------------- /testdata/t.array: -------------------------------------------------------------------------------- 1 | { x[NR] = $0 } 2 | 3 | END { 4 | i = 1 5 | while (i <= NR) { 6 | print x[i] 7 | split (x[i], y) 8 | usage = y[1] 9 | name = y[2] 10 | print " ", name, usage 11 | i++ 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testdata/t.array1: -------------------------------------------------------------------------------- 1 | {for(i=1; i<=NF; i++) { 2 | if (x[$i] == "") 3 | y[++n] = $i 4 | x[$i]++ 5 | } 6 | } 7 | END { 8 | for (i=0; i>> assert failed <<<" 5 | } 6 | 7 | function i(x) { return x } 8 | 9 | { m = length($1); n = length($2); n = i(n); assert(m > n) } 10 | -------------------------------------------------------------------------------- /testdata/t.avg: -------------------------------------------------------------------------------- 1 | {s = s + $1; c = c + 1} 2 | END { 3 | print "sum=", s, " count=", c 4 | print "avg=", s/c 5 | } 6 | -------------------------------------------------------------------------------- /testdata/t.b.x: -------------------------------------------------------------------------------- 1 | {$6=":::" ; print $6; print NF, $0} 2 | -------------------------------------------------------------------------------- /testdata/t.be: -------------------------------------------------------------------------------- 1 | # some question of what FILENAME ought to be before execution. 2 | # current belief: "-", or name of first file argument. 3 | # this may not be sensible. 4 | 5 | BEGIN { print FILENAME } 6 | END { print NR } 7 | -------------------------------------------------------------------------------- /testdata/t.beginexit: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | while (getline && n++ < 10) 3 | print 4 | exit 5 | } 6 | { print } 7 | -------------------------------------------------------------------------------- /testdata/t.beginnext: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | while (getline && n++ < 10) 3 | print 4 | print "tenth" 5 | } 6 | { print } 7 | -------------------------------------------------------------------------------- /testdata/t.break: -------------------------------------------------------------------------------- 1 | { 2 | for (i=1; i <= NF; i++) 3 | if ($i ~ /^[a-z]+$/) { 4 | print $i " is alphabetic" 5 | break 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.break1: -------------------------------------------------------------------------------- 1 | { x[NR] = $0 } 2 | END { 3 | for (i = 1; i <= NR; i++) { 4 | print i, x[i] 5 | if (x[i] ~ /shen/) 6 | break 7 | } 8 | print "got here" 9 | print i, x[i] 10 | } 11 | -------------------------------------------------------------------------------- /testdata/t.break2: -------------------------------------------------------------------------------- 1 | { x[NR] = $0 } 2 | END { 3 | for (i=1; i <= NR; i++) { 4 | print i, x[i] 5 | if (x[i] ~ /shen/) 6 | break 7 | } 8 | print "got here" 9 | print i, x[i] 10 | } 11 | -------------------------------------------------------------------------------- /testdata/t.break3: -------------------------------------------------------------------------------- 1 | { for (i = 1; i <= NF; i++) { 2 | for (j = 1; j <= NF; j++) 3 | if (j == 2) 4 | break; 5 | print "inner", i, j 6 | } 7 | print "outer", i, j 8 | } 9 | -------------------------------------------------------------------------------- /testdata/t.bug1: -------------------------------------------------------------------------------- 1 | # this program fails if awk is created without separate I&D 2 | # prints garbage if no $3 3 | { print $1, $3 } 4 | -------------------------------------------------------------------------------- /testdata/t.builtins: -------------------------------------------------------------------------------- 1 | /^[0-9]/ { print $1, 2 | length($1), 3 | log($1), 4 | sqrt($1), 5 | int(sqrt($1)), 6 | exp($1 % 10) } 7 | -------------------------------------------------------------------------------- /testdata/t.cat: -------------------------------------------------------------------------------- 1 | {print $2 " " $1} 2 | {print $1 " " "is", $2} 3 | {print $2 FS "is" FS $1} 4 | {print length($1 $2), length($1) + length($2)} 5 | -------------------------------------------------------------------------------- /testdata/t.cat1: -------------------------------------------------------------------------------- 1 | {print x $0} # should precede by zero 2 | -------------------------------------------------------------------------------- /testdata/t.cat2: -------------------------------------------------------------------------------- 1 | {$1 = $1 "*"; print} 2 | -------------------------------------------------------------------------------- /testdata/t.cmp: -------------------------------------------------------------------------------- 1 | $2 > $1 2 | -------------------------------------------------------------------------------- /testdata/t.coerce: -------------------------------------------------------------------------------- 1 | END { print i, NR 2 | if (i < NR) 3 | print i, NR 4 | } 5 | -------------------------------------------------------------------------------- /testdata/t.coerce2: -------------------------------------------------------------------------------- 1 | { 2 | print index(1, $1) 3 | print substr(123456789, 1, 3) 4 | print 1 in x 5 | print 1 23 456 6 | print 123456789 ~ 123, 123456789 ~ "abc" 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.comment: -------------------------------------------------------------------------------- 1 | # this is a comment line 2 | # so is this 3 | /#/ { print "this one has a # in it: " $0 # comment 4 | print "again:" $0 5 | } 6 | -------------------------------------------------------------------------------- /testdata/t.comment1: -------------------------------------------------------------------------------- 1 | #comment 2 | # 3 | BEGIN { x = 1 } 4 | /abc/ { print $0 } 5 | #comment 6 | END { print NR } 7 | #comment 8 | -------------------------------------------------------------------------------- /testdata/t.concat: -------------------------------------------------------------------------------- 1 | { x = $1; print x (++i) } 2 | -------------------------------------------------------------------------------- /testdata/t.cond: -------------------------------------------------------------------------------- 1 | { print (substr($2,1,1) > substr($2,2,1)) ? $1 : $2 } 2 | { x = substr($1, 1, 1); y = substr($1, 2, 1); z = substr($1, 3, 1) 3 | print (x > y ? (x > z ? x : z) : y > z ? y : z) } 4 | -------------------------------------------------------------------------------- /testdata/t.contin: -------------------------------------------------------------------------------- 1 | { 2 | for (i = 1; i <= NF; i++) { 3 | if ($i ~ /^[0-9]+$/) 4 | continue; 5 | print $i, " is non-numeric" 6 | next 7 | } 8 | print $0, "is all numeric" 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.count: -------------------------------------------------------------------------------- 1 | END { print NR } 2 | -------------------------------------------------------------------------------- /testdata/t.crlf: -------------------------------------------------------------------------------- 1 | # checks whether lines with crlf are parsed ok 2 | 3 | {print \ 4 | } 5 | -------------------------------------------------------------------------------- /testdata/t.cum: -------------------------------------------------------------------------------- 1 | {i = i + $1; print i} 2 | END { 3 | print i 4 | } 5 | -------------------------------------------------------------------------------- /testdata/t.d.x: -------------------------------------------------------------------------------- 1 | BEGIN {FS=":" ; OFS=":"} 2 | {print NF " ",$0} 3 | -------------------------------------------------------------------------------- /testdata/t.delete1: -------------------------------------------------------------------------------- 1 | { split("1 1.2 abc", x) 2 | x[$1]++ 3 | delete x[1] 4 | delete x[1.2] 5 | delete x["abc"] 6 | delete x[$1] 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.delete2: -------------------------------------------------------------------------------- 1 | NR < 50 { n = split($0, x) 2 | for (i = 1; i <= n; i++) 3 | for (j = 1; j <= n; j++) 4 | y[i,j] = n * i + j 5 | for (i = 1; i <= n; i++) 6 | delete y[i,i] 7 | k = 0 8 | for (i in y) 9 | k++ 10 | if (k != int(n^2-n)) 11 | printf "delete2 miscount %d vs %d at %d\n", k, n^2-n, NR 12 | } 13 | -------------------------------------------------------------------------------- /testdata/t.delete3: -------------------------------------------------------------------------------- 1 | { x[$1] = $1 2 | delete x[$1] 3 | n = 0 4 | for (i in x) n++ 5 | if (n != 0) 6 | print "error", n, "at", NR 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.do: -------------------------------------------------------------------------------- 1 | NF > 0 { 2 | t = $0 3 | gsub(/[ \t]+/, "", t) 4 | n = split($0, y) 5 | if (n > 0) { 6 | i = 1 7 | s = "" 8 | do { 9 | s = s $i 10 | } while (i++ < NF) 11 | } 12 | if (s != t) 13 | print "bad at", NR 14 | } 15 | -------------------------------------------------------------------------------- /testdata/t.e: -------------------------------------------------------------------------------- 1 | $1 < 10 || $2 ~ /bwk/ 2 | -------------------------------------------------------------------------------- /testdata/t.else: -------------------------------------------------------------------------------- 1 | { if($1>1000) print "yes" 2 | else print "no" 3 | } 4 | -------------------------------------------------------------------------------- /testdata/t.exit: -------------------------------------------------------------------------------- 1 | { print } 2 | $1 < 5000 { exit NR } 3 | -------------------------------------------------------------------------------- /testdata/t.exit1: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | print "this is before calling myabort" 3 | myabort(1) 4 | print "this is after calling myabort" 5 | } 6 | function myabort(n) { 7 | print "in myabort - before exit", n 8 | exit 2 9 | print "in myabort - after exit" 10 | } 11 | END { 12 | print "into END" 13 | myabort(2) 14 | print "should not see this" 15 | } 16 | -------------------------------------------------------------------------------- /testdata/t.f: -------------------------------------------------------------------------------- 1 | {print $2, $1} 2 | -------------------------------------------------------------------------------- /testdata/t.f.x: -------------------------------------------------------------------------------- 1 | $1>0 {print $1, sqrt($1)} 2 | -------------------------------------------------------------------------------- /testdata/t.f0: -------------------------------------------------------------------------------- 1 | $1 ~ /x/ {print $0} 2 | -------------------------------------------------------------------------------- /testdata/t.f1: -------------------------------------------------------------------------------- 1 | {$1 = 1; print} 2 | -------------------------------------------------------------------------------- /testdata/t.f2: -------------------------------------------------------------------------------- 1 | {$1 = 1; print $0} 2 | -------------------------------------------------------------------------------- /testdata/t.f3: -------------------------------------------------------------------------------- 1 | {$1 = NR; print} 2 | -------------------------------------------------------------------------------- /testdata/t.f4: -------------------------------------------------------------------------------- 1 | {$1 = NR; print $0} 2 | -------------------------------------------------------------------------------- /testdata/t.for: -------------------------------------------------------------------------------- 1 | { for (i=1; i<=NF; i++) 2 | print i, $i 3 | } 4 | -------------------------------------------------------------------------------- /testdata/t.for1: -------------------------------------------------------------------------------- 1 | { 2 | i = 1 3 | for (;;) { 4 | if (i > NF) 5 | next 6 | print i, $i 7 | i++ 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.for2: -------------------------------------------------------------------------------- 1 | { 2 | for (i=1;;i++) { 3 | if (i > NF) 4 | next 5 | print i, $i 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.for3: -------------------------------------------------------------------------------- 1 | { for (i = 1; length($i) > 0; i++) 2 | print i, $i 3 | } 4 | { for (i = 1; 5 | length($i) > 0; 6 | i++) 7 | print $i 8 | } 9 | -------------------------------------------------------------------------------- /testdata/t.format4: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | text=sprintf ("%125s", "x") 3 | print length (text) 4 | print text 5 | xxx=substr (text,1,105) 6 | print length (xxx) 7 | print xxx 8 | exit 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.fun: -------------------------------------------------------------------------------- 1 | function g() { return "{" f() "}" } 2 | function f() { return $1 } 3 | { print "<" g() ">" } 4 | -------------------------------------------------------------------------------- /testdata/t.fun0: -------------------------------------------------------------------------------- 1 | function f(a) { print "hello"; return a } 2 | { print "<" f($1) ">" } 3 | -------------------------------------------------------------------------------- /testdata/t.fun1: -------------------------------------------------------------------------------- 1 | function f(a,b,c) { print "hello" } 2 | NR < 3 { f(1,2,3) } 3 | -------------------------------------------------------------------------------- /testdata/t.fun2: -------------------------------------------------------------------------------- 1 | function f(n) { 2 | while (n < 10) { 3 | print n 4 | n = n + 1 5 | } 6 | } 7 | function g(n) { 8 | print "g", n 9 | } 10 | { f($1); g($1); print n } 11 | -------------------------------------------------------------------------------- /testdata/t.fun3: -------------------------------------------------------------------------------- 1 | function f(n) { while ((n /= 10) > 1) print n } 2 | function g(n) { print "g", n } 3 | { f($1); g($1) } 4 | -------------------------------------------------------------------------------- /testdata/t.fun4: -------------------------------------------------------------------------------- 1 | function f(a, n) { 2 | for (i=1; i <= n; i++) 3 | print " " a[i] 4 | } 5 | 6 | { print 7 | n = split($0, x) 8 | f(x, n) 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.fun5: -------------------------------------------------------------------------------- 1 | function f(a) { 2 | return split($0, a) 3 | } 4 | { 5 | print 6 | n = f(x) 7 | for (i = 1; i <= n; i++) 8 | print " " x[i] 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.getval: -------------------------------------------------------------------------------- 1 | { # tests various resetting of $1, $0, etc. 2 | 3 | $1 = length($1) + length($2) 4 | print $0 + 0 5 | 6 | } 7 | -------------------------------------------------------------------------------- /testdata/t.gsub: -------------------------------------------------------------------------------- 1 | {gsub(/[aeiou]/,"foo"); print} 2 | -------------------------------------------------------------------------------- /testdata/t.gsub1: -------------------------------------------------------------------------------- 1 | {gsub(/$/,"x"); print} 2 | -------------------------------------------------------------------------------- /testdata/t.gsub3: -------------------------------------------------------------------------------- 1 | length($1) {gsub(substr($1,1,1),"(&)"); print} 2 | -------------------------------------------------------------------------------- /testdata/t.gsub4: -------------------------------------------------------------------------------- 1 | length($1) == 0 { next } 2 | 3 | {gsub("[" $1 "]","(&)"); print} 4 | {gsub("[" $1 "]","(\\&)"); print} 5 | -------------------------------------------------------------------------------- /testdata/t.i.x: -------------------------------------------------------------------------------- 1 | $1+0 > 0 {i=i+log($1); print i,log($1)} 2 | END {print i} 3 | -------------------------------------------------------------------------------- /testdata/t.if: -------------------------------------------------------------------------------- 1 | {if($1 || $2) print} 2 | -------------------------------------------------------------------------------- /testdata/t.in: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | x["apple"] = 1; 3 | x["orange"] = 2; 4 | x["lemon"] = 3; 5 | for (i in x) 6 | print i, x[i] | "sort" 7 | close("sort") 8 | exit 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.in1: -------------------------------------------------------------------------------- 1 | { if (amount[$2] == "") 2 | name[++n] = $2 3 | amount[$2] += $1 4 | } 5 | END { for (i in name) 6 | print i, name[i], amount[name[i]] | "sort" 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.in2: -------------------------------------------------------------------------------- 1 | { x[substr($2, 1, 1)] += $1 } 2 | END { for (i in x) 3 | print i, x[i] 4 | } 5 | -------------------------------------------------------------------------------- /testdata/t.in3: -------------------------------------------------------------------------------- 1 | { x[NR] = $0 } 2 | END { 3 | for (i in x) 4 | if (x[i] ~ /shen/) 5 | break 6 | print i, x[i] 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.incr: -------------------------------------------------------------------------------- 1 | { ++i; --j; k++; l-- } 2 | END { print NR, i, j, k, l } 3 | -------------------------------------------------------------------------------- /testdata/t.incr2: -------------------------------------------------------------------------------- 1 | { s = 0 2 | for (i=1; i <= NF; ) 3 | if ($(i) ~ /^[0-9]+$/) 4 | s += $(i++) 5 | else 6 | i++ 7 | print s 8 | } 9 | -------------------------------------------------------------------------------- /testdata/t.incr3: -------------------------------------------------------------------------------- 1 | { s = 0 2 | for (i=1; i <= NF; s += $(i++)) 3 | ; 4 | print s 5 | } 6 | -------------------------------------------------------------------------------- /testdata/t.index: -------------------------------------------------------------------------------- 1 | { n = length 2 | d = 0 3 | for (i = 1; i <= n; i++) 4 | if ((k = index($0, substr($0, i))) != i) { 5 | d = 1 6 | break; 7 | } 8 | if (d) 9 | print $0, "has duplicate letters" 10 | } 11 | -------------------------------------------------------------------------------- /testdata/t.intest: -------------------------------------------------------------------------------- 1 | { 2 | line = substr($0, index($0, " ")) 3 | print line 4 | n = split(line, x) 5 | if ($1 in x) 6 | print "yes" 7 | else 8 | print "no" 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.intest2: -------------------------------------------------------------------------------- 1 | { 2 | line = substr($0, index($0, " ")) 3 | print line 4 | n = split(line, x) 5 | x[$0, $1] = $0 6 | print x[$0, $1] 7 | print "<<<" 8 | for (i in x) print i, x[i] 9 | print ">>>" 10 | if (($0,$1) in x) 11 | print "yes" 12 | if ($1 in x) 13 | print "yes" 14 | else 15 | print "no" 16 | } 17 | -------------------------------------------------------------------------------- /testdata/t.j.x: -------------------------------------------------------------------------------- 1 | {i=i+sqrt($1); print i,sqrt($1)} 2 | END {print sqrt(i),i} 3 | -------------------------------------------------------------------------------- /testdata/t.longstr: -------------------------------------------------------------------------------- 1 | BEGIN{ 2 | x = "111111111122222222233333333334444444444555555555566666666667777777777888888888899999999990000000000" 3 | printf "%s\n", x 4 | exit 5 | } 6 | -------------------------------------------------------------------------------- /testdata/t.makef: -------------------------------------------------------------------------------- 1 | {$3 = 2*$1; print $1, $2, $3} 2 | -------------------------------------------------------------------------------- /testdata/t.match: -------------------------------------------------------------------------------- 1 | $2 ~ /ava|bwk/ 2 | -------------------------------------------------------------------------------- /testdata/t.match1: -------------------------------------------------------------------------------- 1 | NF > 0 && match($NF, $1) { 2 | print $0, RSTART, RLENGTH 3 | if (RLENGTH != length($1)) 4 | printf "match error at %d: %d %d\n", 5 | NR, RLENGTH, RSTART >"/dev/tty" 6 | } 7 | -------------------------------------------------------------------------------- /testdata/t.max: -------------------------------------------------------------------------------- 1 | length > max { max = length; x = $0} 2 | END { print max, x } 3 | -------------------------------------------------------------------------------- /testdata/t.mod: -------------------------------------------------------------------------------- 1 | NR % 2 == 1 2 | -------------------------------------------------------------------------------- /testdata/t.monotone: -------------------------------------------------------------------------------- 1 | /^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?$/ 2 | -------------------------------------------------------------------------------- /testdata/t.nameval: -------------------------------------------------------------------------------- 1 | { if (amount[$2] == "") 2 | name[++n] = $2 3 | amount[$2] += $1 4 | } 5 | END { for (i = 1; i <= n; i++) 6 | print name[i], amount[name[i]] 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.next: -------------------------------------------------------------------------------- 1 | $1 > 5000 { next } 2 | { print } 3 | -------------------------------------------------------------------------------- /testdata/t.not: -------------------------------------------------------------------------------- 1 | $2 !~ /ava|bwk/ 2 | !($1 < 2000) 3 | !($2 ~ /bwk/) 4 | !$2 ~ /bwk/ 5 | -------------------------------------------------------------------------------- /testdata/t.null0: -------------------------------------------------------------------------------- 1 | BEGIN { FS = ":" } 2 | { if (a) print "a", a 3 | if (b == 0) print "b", b 4 | if ( c == "0") print "c", c 5 | if (d == "") print "d", d 6 | if (e == 1-1) print "e", e 7 | } 8 | $1 == 0 {print "$1 = 0"} 9 | $1 == "0" {print "$1 = quoted 0"} 10 | $1 == "" {print "$1 = null string"} 11 | $5 == 0 {print "$5 = 0"} 12 | $5 == "0" {print "$5 = quoted 0"} 13 | $5 == "" {print "$5 = null string"} 14 | $1 == $3 {print "$1 = $3"} 15 | $5 == $6 {print "$5 = $6"} 16 | -------------------------------------------------------------------------------- /testdata/t.ofmt: -------------------------------------------------------------------------------- 1 | BEGIN {OFMT="%.5g"} 2 | {print $1+0} 3 | -------------------------------------------------------------------------------- /testdata/t.ofs: -------------------------------------------------------------------------------- 1 | BEGIN { OFS = " %% "; ORS = "##" } 2 | { print $1, $2; print } 3 | -------------------------------------------------------------------------------- /testdata/t.ors: -------------------------------------------------------------------------------- 1 | BEGIN {ORS="abc"} 2 | {print $1, $2, $3} 3 | -------------------------------------------------------------------------------- /testdata/t.pat: -------------------------------------------------------------------------------- 1 | /a/ || /b/ 2 | /a/ && /b/ 3 | /a/ && NR > 10 4 | /a/ || NR > 10 5 | -------------------------------------------------------------------------------- /testdata/t.pipe: -------------------------------------------------------------------------------- 1 | BEGIN {print "read /usr/bwk/awk/t.pipe" | "cat"} 2 | -------------------------------------------------------------------------------- /testdata/t.pp: -------------------------------------------------------------------------------- 1 | /a/,/b/ 2 | -------------------------------------------------------------------------------- /testdata/t.pp1: -------------------------------------------------------------------------------- 1 | /bwk/,/bwk/ { print $2, $1 } 2 | /ava/,/ava/ { print $2, $1 } 3 | /pjw/,/pjw/ { print $2, $1 } 4 | -------------------------------------------------------------------------------- /testdata/t.pp2: -------------------------------------------------------------------------------- 1 | /bwk/,/scj/ { print "1: ", $0 } 2 | /bwk/, /bsb/ { print "2: ", $0 } 3 | /mel/, /doug/ { print "3: ", $0 } 4 | -------------------------------------------------------------------------------- /testdata/t.printf: -------------------------------------------------------------------------------- 1 | { 2 | printf "%%: %s ... %s \t", $2, $1 3 | x = sprintf("%8d %10.10s", $1, $2) 4 | print x 5 | } 6 | -------------------------------------------------------------------------------- /testdata/t.printf2: -------------------------------------------------------------------------------- 1 | { 2 | printf "%%: %s ... %s \t", $2, $1 3 | x = sprintf("%8d %10.10s %u %o %x", $1, $2, $3, $3, $3*$4) 4 | x = x sprintf(" %c %c", $1, $2) 5 | print x 6 | } 7 | -------------------------------------------------------------------------------- /testdata/t.quote: -------------------------------------------------------------------------------- 1 | {print "\"" $1 "\""} 2 | -------------------------------------------------------------------------------- /testdata/t.randk: -------------------------------------------------------------------------------- 1 | { 2 | k = 2 3 | n = NF 4 | i = 1 5 | while ( i <= n ) { 6 | if ( rand() < k/n ) { 7 | print i 8 | k-- 9 | } 10 | n-- 11 | i++ 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /testdata/t.re1: -------------------------------------------------------------------------------- 1 | /[a-cg-j1-3]/ { print $0 " matches /[a-cg-j1-3]/" } 2 | /[^aeiou]/ { print $0 " matches /[^aeiou]/" } 3 | -------------------------------------------------------------------------------- /testdata/t.re1a: -------------------------------------------------------------------------------- 1 | BEGIN { r1 = "[a-cg-j1-3]" 2 | r2 = "[^aeiou]" 3 | } 4 | 5 | $0 ~ r1 { print $0 " matches /[a-cg-j1-3]/" } 6 | $0 ~ r2 { print $0 " matches /[^aeiou]/" } 7 | -------------------------------------------------------------------------------- /testdata/t.re2: -------------------------------------------------------------------------------- 1 | /[a-z]()[0-9]/ 2 | !/^$/ 3 | -------------------------------------------------------------------------------- /testdata/t.re3: -------------------------------------------------------------------------------- 1 | { r1 = $1 2 | r2 = $1 ":" 3 | } 4 | 5 | length(r1) && $0 ~ r1 { print $0 " matches " r1 } 6 | length(r1) && $0 ~ r2 { print $0 " matches " r2 } 7 | -------------------------------------------------------------------------------- /testdata/t.re4: -------------------------------------------------------------------------------- 1 | BEGIN { r1 = "xxx" 2 | r2 = "xxx" ":" 3 | r3 = ":" r2 4 | r4 = "a" 5 | } 6 | 7 | $0 ~ r1 { print $0 " matches " r1 } 8 | $0 ~ r2 { print $0 " matches " r2 } 9 | $0 ~ r3 { print $0 " matches " r3 } 10 | $0 ~ r4 { print $0 " matches " r4 } 11 | -------------------------------------------------------------------------------- /testdata/t.re5: -------------------------------------------------------------------------------- 1 | BEGIN { for (i = 0; i <= 9; i++) r[i] = i } 2 | 3 | { for (i in r) if ($0 ~ r[i]) print } 4 | -------------------------------------------------------------------------------- /testdata/t.re7: -------------------------------------------------------------------------------- 1 | /^([0-9]+\.?[0-9]*|\.[0-9]+)((e|E)(\+|-)?[0-9]+)?$/ 2 | -------------------------------------------------------------------------------- /testdata/t.reFS: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "\t+" } 2 | { print $1, $2 } 3 | -------------------------------------------------------------------------------- /testdata/t.rec: -------------------------------------------------------------------------------- 1 | { print sqrt($1) } 2 | -------------------------------------------------------------------------------- /testdata/t.reg: -------------------------------------------------------------------------------- 1 | /[^\[\]]/ 2 | !/^\[/ 3 | !/^[\[\]]/ 4 | /[\[\]]/ 5 | -------------------------------------------------------------------------------- /testdata/t.roff: -------------------------------------------------------------------------------- 1 | NF > 0 { 2 | for (i = 1; i <= NF; i++) { 3 | n = length($i) 4 | if (n + olen >= 60) { 5 | print oline 6 | olen = n 7 | oline = $i 8 | } else { 9 | oline = oline " " $i 10 | olen += n 11 | } 12 | } 13 | } 14 | 15 | NF == 0 { 16 | print oline 17 | olen = 0 18 | } 19 | 20 | END { 21 | if (olen > 0) 22 | print oline 23 | } 24 | -------------------------------------------------------------------------------- /testdata/t.sep: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "1"; print "field separator is", FS } 2 | NF>1 { print $0 " has " NF " fields" } 3 | -------------------------------------------------------------------------------- /testdata/t.seqno: -------------------------------------------------------------------------------- 1 | {print NR, $0} 2 | -------------------------------------------------------------------------------- /testdata/t.set0: -------------------------------------------------------------------------------- 1 | {$0 = $1; print; print NF, $0; print $2} 2 | {$(0) = $1; print; print NF, $0; print $2} 3 | { i = 1; $(i) = $i+1; print } 4 | -------------------------------------------------------------------------------- /testdata/t.set0a: -------------------------------------------------------------------------------- 1 | {$0 = $2; print; print NF, $0; print $1} 2 | -------------------------------------------------------------------------------- /testdata/t.set0b: -------------------------------------------------------------------------------- 1 | {x=$1 = $0 = $2; print } 2 | {$0 = $2 = $1; print } 3 | {$(0) = $(2) = $(1); print } 4 | -------------------------------------------------------------------------------- /testdata/t.set1: -------------------------------------------------------------------------------- 1 | function f(x) { x = 1; print x } 2 | { f($0) 3 | f($1) } 4 | -------------------------------------------------------------------------------- /testdata/t.set2: -------------------------------------------------------------------------------- 1 | { n = length($0) % 2 2 | $n = $2 3 | print 4 | } 5 | -------------------------------------------------------------------------------- /testdata/t.set3: -------------------------------------------------------------------------------- 1 | { i = 1; $i = $i/10; print } 2 | -------------------------------------------------------------------------------- /testdata/t.split2: -------------------------------------------------------------------------------- 1 | { split ($0, x); print x[2], x[1] } 2 | -------------------------------------------------------------------------------- /testdata/t.split2a: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | a[1]="a b" 3 | print split(a[1],a),a[1],a[2] 4 | } 5 | -------------------------------------------------------------------------------- /testdata/t.split3: -------------------------------------------------------------------------------- 1 | { a = $0 " " $0 " " $0 2 | if ($1 != "") 3 | n = split (a, x, "[" $1 "]") 4 | print n, x[1], x[2], x[3], x[4] } 5 | -------------------------------------------------------------------------------- /testdata/t.split4: -------------------------------------------------------------------------------- 1 | { a = $0 " " $0 " " $0 " " 123 2 | n = split (a, x, /[ \t][ \t]*/) 3 | print n, x[1], x[2], x[3], x[4] 4 | } 5 | -------------------------------------------------------------------------------- /testdata/t.split8: -------------------------------------------------------------------------------- 1 | { 2 | n = split ($0, x, /[ ]+/) 3 | print n 4 | if (n != NF) 5 | print "split botch at ", NR, n, NF 6 | for (i=1; i<=n; i++) 7 | if ($i != x[i]) 8 | print "different element at ", i, x[i], $i 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.split9: -------------------------------------------------------------------------------- 1 | { 2 | n = split ($0, x, FS) 3 | if (n != NF) 4 | print "botch at ", NR, n, NF 5 | for (i=1; i<=n; i++) 6 | if ($i != x[i]) 7 | print "diff at ", i, x[i], $i 8 | } 9 | -------------------------------------------------------------------------------- /testdata/t.split9a: -------------------------------------------------------------------------------- 1 | BEGIN { FS = "a" } 2 | { 3 | n = split ($0, x, FS) 4 | if (n != NF) 5 | print "botch at ", NR, n, NF 6 | for (i=1; i<=n; i++) 7 | if ($i != x[i]) 8 | print "diff at ", i, x[i], $i 9 | } 10 | -------------------------------------------------------------------------------- /testdata/t.stately: -------------------------------------------------------------------------------- 1 | /^(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)*$/ 2 | -------------------------------------------------------------------------------- /testdata/t.strcmp: -------------------------------------------------------------------------------- 1 | $2 >= "ava" && $2 <= "bwk" || $2 >= "pjw" 2 | -------------------------------------------------------------------------------- /testdata/t.strcmp1: -------------------------------------------------------------------------------- 1 | $1 != 1 && $1 != 2 && $1 != 3 && $1 != 4 && $1 != 5 2 | -------------------------------------------------------------------------------- /testdata/t.strnum: -------------------------------------------------------------------------------- 1 | BEGIN { print 1E2 "", 12e-2 "", e12 "", 1.23456789 "" } 2 | -------------------------------------------------------------------------------- /testdata/t.sub1: -------------------------------------------------------------------------------- 1 | {sub(/.$/,"x"); print} 2 | -------------------------------------------------------------------------------- /testdata/t.sub2: -------------------------------------------------------------------------------- 1 | {sub(/.$/,"&&"); print} 2 | {sub(/.$/,"&\\&&"); print} 3 | -------------------------------------------------------------------------------- /testdata/t.sub3: -------------------------------------------------------------------------------- 1 | length($1) {sub(substr($1,1,1),"(&)"); print} 2 | -------------------------------------------------------------------------------- /testdata/t.substr: -------------------------------------------------------------------------------- 1 | substr($2, 1, 1) ~ /[abc]/ 2 | substr($2, length($2)) !~ /[a-z]/ 3 | substr($2, length($2)) ~ /./ 4 | -------------------------------------------------------------------------------- /testdata/t.substr1: -------------------------------------------------------------------------------- 1 | NR % 2 { print substr($0, 0, -1) } 2 | -------------------------------------------------------------------------------- /testdata/t.time: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | FS = "-" 3 | } 4 | /sh$/ { 5 | n++ 6 | l = length($NF) 7 | s += l 8 | ck %= l 9 | totck += ck 10 | print 11 | } 12 | END { 13 | if (n > 0) { 14 | printf "%d %d %d %fn\n", totck, n, s, s/n 15 | } 16 | else 17 | print "n is zero" 18 | } 19 | -------------------------------------------------------------------------------- /testdata/t.vf: -------------------------------------------------------------------------------- 1 | BEGIN { i = 1 } 2 | {print $(i+i)} 3 | {print $(1)} 4 | -------------------------------------------------------------------------------- /testdata/t.vf1: -------------------------------------------------------------------------------- 1 | { print 2 | i = 1 3 | while (i <= NF) { 4 | print " " $i 5 | i = i + 1 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /testdata/t.vf2: -------------------------------------------------------------------------------- 1 | { print $NF++; print $NF } 2 | -------------------------------------------------------------------------------- /testdata/t.vf3: -------------------------------------------------------------------------------- 1 | BEGIN { i=1; j=2 } 2 | {$i = $j; print} 3 | -------------------------------------------------------------------------------- /testdata/t.x: -------------------------------------------------------------------------------- 1 | /x/ 2 | -------------------------------------------------------------------------------- /testdata/test.countries: -------------------------------------------------------------------------------- 1 | Russia 8650 262 Asia 2 | Canada 3852 24 North America 3 | China 3692 866 Asia 4 | USA 3615 219 North America 5 | Brazil 3286 116 South America 6 | Australia 2968 14 Australia 7 | India 1269 637 Asia 8 | Argentina 1072 26 South America 9 | Sudan 968 19 Africa 10 | Algeria 920 18 Africa 11 | -------------------------------------------------------------------------------- /testdata/tt.01_print: -------------------------------------------------------------------------------- 1 | { print } 2 | -------------------------------------------------------------------------------- /testdata/tt.02_print_NR_NF: -------------------------------------------------------------------------------- 1 | { print NR, NF, $0 } 2 | -------------------------------------------------------------------------------- /testdata/tt.02a_print_length: -------------------------------------------------------------------------------- 1 | { $2 = length($2); print } 2 | -------------------------------------------------------------------------------- /testdata/tt.03_sum_length: -------------------------------------------------------------------------------- 1 | { s += length($2) } 2 | END { print s } 3 | -------------------------------------------------------------------------------- /testdata/tt.03a_sum_field: -------------------------------------------------------------------------------- 1 | { s += $3 } 2 | END { print s } 3 | -------------------------------------------------------------------------------- /testdata/tt.04_printf_fields: -------------------------------------------------------------------------------- 1 | { for (i = NF; i > 0; i--) 2 | printf "%s ", $i 3 | } 4 | -------------------------------------------------------------------------------- /testdata/tt.05_concat_fields: -------------------------------------------------------------------------------- 1 | { 2 | s = "" 3 | for (i = NF; i > 0; i--) 4 | s = s " " $i 5 | print s 6 | } 7 | -------------------------------------------------------------------------------- /testdata/tt.06_count_lengths: -------------------------------------------------------------------------------- 1 | { 2 | x[$1] += length 3 | } 4 | END { 5 | for (i in x) 6 | print i, x[i] | "sort" 7 | } 8 | -------------------------------------------------------------------------------- /testdata/tt.07_even_fields: -------------------------------------------------------------------------------- 1 | NF % 2 == 0 2 | -------------------------------------------------------------------------------- /testdata/tt.08_even_lengths: -------------------------------------------------------------------------------- 1 | length % 2 == 0 2 | -------------------------------------------------------------------------------- /testdata/tt.08z_regex_simple: -------------------------------------------------------------------------------- 1 | /foo.*d/ { n++ } END { print n } 2 | -------------------------------------------------------------------------------- /testdata/tt.09_regex_starts_with: -------------------------------------------------------------------------------- 1 | ! /^./ 2 | -------------------------------------------------------------------------------- /testdata/tt.10_regex_ends_with: -------------------------------------------------------------------------------- 1 | /.$/ 2 | -------------------------------------------------------------------------------- /testdata/tt.10a_regex_ends_with_var: -------------------------------------------------------------------------------- 1 | BEGIN { x = ".$" } 2 | $0 ~ x 3 | -------------------------------------------------------------------------------- /testdata/tt.11_substr: -------------------------------------------------------------------------------- 1 | { print substr($0, 10,10) } 2 | -------------------------------------------------------------------------------- /testdata/tt.12_update_fields: -------------------------------------------------------------------------------- 1 | { $3 = "xxx" $3 "xxx"; $4--; print } 2 | -------------------------------------------------------------------------------- /testdata/tt.13_array_ops: -------------------------------------------------------------------------------- 1 | { for (i = 1; i <= NF; i++) 2 | x[i] = $i 3 | for (i = 1; i <= NF; i++) 4 | print x[i] 5 | } 6 | -------------------------------------------------------------------------------- /testdata/tt.13a_array_printf: -------------------------------------------------------------------------------- 1 | { for (i = 1; i <= NF; i++) 2 | x[i] = $i 3 | for (i = 1; i <= NF; i++) 4 | printf "%d %s\n", i, x[i] 5 | } 6 | -------------------------------------------------------------------------------- /testdata/tt.14_function_call: -------------------------------------------------------------------------------- 1 | function abs(x) { return (x < 0) ? -x : x } 2 | BEGIN { n = 1000 3 | for (i = 1; i < n; i++) x[i] = rand() 4 | for (i in x) 5 | for (j in x) 6 | if (abs(x[i]-x[j]) < .01) break 7 | } 8 | -------------------------------------------------------------------------------- /testdata/tt.16_count_words: -------------------------------------------------------------------------------- 1 | 2 | { for (i = 1; i <= NF; i++) 3 | w[$i]++ 4 | } 5 | 6 | END { for (i in w) print w[i], i | "sort -nr" } 7 | -------------------------------------------------------------------------------- /testdata/tt.x2_sum_loop: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | for (i=0; i<10000000; i++) { 3 | sum += i*2 4 | } 5 | print sum 6 | } -------------------------------------------------------------------------------- /testdata/wildcards/a.awk: -------------------------------------------------------------------------------- 1 | FNR==1 { print FILENAME } 2 | -------------------------------------------------------------------------------- /testdata/wildcards/b.awk: -------------------------------------------------------------------------------- 1 | FNR==1 { print "bee" } 2 | -------------------------------------------------------------------------------- /testdata/wildcards/one.txt: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | -------------------------------------------------------------------------------- /testdata/wildcards/two.txt: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | --------------------------------------------------------------------------------