gawk: Library Functions

1 
1 10 A Library of 'awk' Functions
1 *******************************
1 
1 ⇒User-defined describes how to write your own 'awk' functions.
1 Writing functions is important, because it allows you to encapsulate
1 algorithms and program tasks in a single place.  It simplifies
1 programming, making program development more manageable and making
1 programs more readable.
1 
1    In their seminal 1976 book, 'Software Tools',(1) Brian Kernighan and
1 P.J. Plauger wrote:
1 
1      Good Programming is not learned from generalities, but by seeing
1      how significant programs can be made clean, easy to read, easy to
1      maintain and modify, human-engineered, efficient and reliable, by
1      the application of common sense and good programming practices.
1      Careful study and imitation of good programs leads to better
1      writing.
1 
1    In fact, they felt this idea was so important that they placed this
1 statement on the cover of their book.  Because we believe strongly that
1 their statement is correct, this major node and ⇒Sample Programs,
1 provide a good-sized body of code for you to read and, we hope, to learn
1 from.
1 
1    This major node presents a library of useful 'awk' functions.  Many
1 of the sample programs presented later in this Info file use these
1 functions.  The functions are presented here in a progression from
1 simple to complex.
1 
1    ⇒Extract Program presents a program that you can use to
1 extract the source code for these example library functions and programs
1 from the Texinfo source for this Info file.  (This has already been done
1 as part of the 'gawk' distribution.)
1 
1    If you have written one or more useful, general-purpose 'awk'
1 functions and would like to contribute them to the 'awk' user community,
1 see ⇒How To Contribute, for more information.
1 
1    The programs in this major node and in ⇒Sample Programs,
1 freely use 'gawk'-specific features.  Rewriting these programs for
1 different implementations of 'awk' is pretty straightforward:
1 
1    * Diagnostic error messages are sent to '/dev/stderr'.  Use '| "cat
1      1>&2"' instead of '> "/dev/stderr"' if your system does not have a
1      '/dev/stderr', or if you cannot use 'gawk'.
1 
1    * A number of programs use 'nextfile' (⇒Nextfile Statement) to
1      skip any remaining input in the input file.
1 
1    * Finally, some of the programs choose to ignore upper- and lowercase
1      distinctions in their input.  They do so by assigning one to
1      'IGNORECASE'.  You can achieve almost the same effect(2) by adding
1      the following rule to the beginning of the program:
1 
1           # ignore case
1           { $0 = tolower($0) }
1 
1      Also, verify that all regexp and string constants used in
1      comparisons use only lowercase letters.
1 

Menu