runawk

small wrapper for AWK interpreter
Download

runawk Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Aleksey Cheusov
  • Publisher web site:

runawk Tags


runawk Description

small wrapper for AWK interpreter runawk is a tiny wrapper for AWK interpreter that impements module system and helps to write the standalone AWK programs.MOTIVATIONAfter years of using AWK for programming I've found that despite ofits simplicity and limitations AWK is good enough for scripting a widerange of different tasks. AWK is not as poweful as their biggercounterparts like Perl, Ruby, TCL and others but it has their ownadvantages like compactness, simplicity and availability on almost allUNIX-like systems. I personally also like its data-driven nature andtoken orientation, very useful technique for simple text processingutilities.But! Unfortunately awk interpreters lacks some important features andsometimes work not as good as it whould be.Some problems I see (some of them, of course).1) AWK lacks support for modules. Even if I create small programs, Ioften want to use the functions created earlier and already used inother scripts. That is, it whould great to orginise functions intoso called libraries (modules).2) In order to pass arguments to #!/usr/bin/awk -f script (not to awkinterpreter), it is necessary to prepand a list ofarguments with -- (two minus signes). In my view, this looks badly.Example:awk_program: #!/usr/bin/awk -f BEGIN { for (i=1; i < ARGC; i){ printf "ARGV =%s ", i, ARGV } }Shell session: % awk_program --opt1 --opt2 /usr/bin/awk: unknown option --opt1 ignored /usr/bin/awk: unknown option --opt2 ignored % awk_program -- --opt1 --opt2 ARGV =--opt1 ARGV =--opt2 %In my opinion awk_program script should work like this (just likenormal programs do) % awk_program --opt1 --opt2 ARGV =--opt1 ARGV =--opt2 %It is possible using runawk.3) When #!/usr/bin/awk -f script handles arguments (options) and wantsto read from stdin, it is necessary to add/dev/stdin (or `-') as a last argument explicitely.Example:awk_program: #!/usr/bin/awk -f BEGIN { if (ARGV == "--flag"){ flag = 1 ARGV = "" # to not read file named "--flag" } } { print "flag=" flag " $0=" $0 }Shell session: % echo test | awk_program -- --flag % echo test | awk_program -- --flag /dev/stdin flag=1 $0=test %Ideally awk_program should work like this % echo test | awk_program --flag flag=1 $0=test %All these probles are solved by runawk and this is why I wrote it.I also include a few modules to runawk distribution which areuseful for me and I hope will be helpful for you too.INSTALLATION0) BSD make is required. I name it just 'make' but its real name may vary. bmake and pmake are possible names. If you need to change the default building options, run make like this env make < target > See example section below1) Uncompress tarball you've downloaded like this gzip -dc runawk-X-Y-Z.tar.gz | tar -xf-2) cd runawk-X-Y-Z3) make4) (optional!) make install-dirs5) make installThere are a lot of Makefile variables that can be changed duringinstallation. Runawk's own variables (All they are at the begining ofMakefile): PREFIX - where runawk is installed to MODULESDIR - directory where modules are installed to AWK_PROG - path to awk interpreter STDIN_FILENAME - path to stdin device fileBSD make's variables (most commonly used,for all others - see make's documentation and .mk files) BINDIR - where runawk executable itself is installed to MANDIR - where manual pages are installed to BINOWN - runawk executable owner BINGRP - runawk executable group MANOWN - man page owner MANGRP - man page groupExample: env CC=gcc PREFIX=/home/cheusov/local LDFLAGS='-L/usr/pkg/lib -Wl,-rpath -Wl,/usr/pkg/lib' LDADD=-lextralib CFLAGS='-Werror -Wall' CPPFLAGS=-I/usr/pkg/include BINOWN=cheusov BINGRP=users MANOWN=cheusov MANGRP=users MKCATPAGES=no make -s all install-dirs install What's New in This Release: · Lots of demo programs for most runawk modules were created and they are in examples/ subdirectory now. New MEGA module ;-) power_getopt.awk See the documentation and demo program examples/demo_power_getopt. It makes options handling REALLY easy. New modules: embed_str.awk has_suffix.awk has_prefix.awk readfile.awk modinfo.awk Minor fixes and improvements in dirname.awk and basename.awk. Now they are fully compatible with dirname(1) and basename(1) RUNAWK sets the following environment variables for the child awk subprocess: RUNAWK_MODC - A number of modules (-f filename) passed to AWK RUNAWK_MODV_ - Full path to the module #n, where n is in [0..RUNAWK_MODC) range. RUNAWK sets RUNAWK_ART_STDIN environment variable for the child awk subprocess to 1 if additional/artificial `-' was added to the list to awk's arguments. Makefile: bmake-ism were removed. Now Makefile is fully compatible with FreeBSD make. CLEANFILES target is used instead of hand-made rules Minor fix in 'test_all' target


runawk Related Software