Next: , Previous: Advanced Features, Up: Top


12 A Library of awk Functions

User-defined, describes how to write your own awk functions. Writing functions is important, because it allows you to encapsulate algorithms and program tasks in a single place. It simplifies programming, making program development more manageable, and making programs more readable.

One valuable way to learn a new programming language is to read programs in that language. To that end, this chapter and Sample Programs, provide a good-sized body of code for you to read, and hopefully, to learn from.

This chapter presents a library of useful awk functions. Many of the sample programs presented later in this Web page use these functions. The functions are presented here in a progression from simple to complex.

Extract Program, presents a program that you can use to extract the source code for these example library functions and programs from the Texinfo source for this Web page. (This has already been done as part of the gawk distribution.)

If you have written one or more useful, general-purpose awk functions and would like to contribute them to the awk user community, see How To Contribute, for more information.

The programs in this chapter and in Sample Programs, freely use features that are gawk-specific. Rewriting these programs for different implementations of awk is pretty straightforward.


Footnotes

[1] The effects are not identical. Output of the transformed record will be in all lowercase, while IGNORECASE preserves the original contents of the input record.