11.8. Gawk-specific FeaturesThis section describes features unique to gawk. 11.8.1. Coprocesses and Socketsgawk allows you to open a two-way pipe to another process, called a coprocess. This is done with the |& operator used with getline and print or printf. print database command |& "db_server" "db_server" |& getline response If the command used with |& is a filename beginning with /inet/, gawk opens a TCP/IP connection. The filename should be of the following form: /inet/protocol/lport/hostname/rport The parts of the filename are:
11.8.2. ProfilingWhen gawk is built and installed, a separate program named pgawk (profiling gawk) is built and installed with it. The two programs behave identically; however, pgawk runs more slowly because it keeps execution counts for each statement as it runs. When it is done, it automatically places an execution profile of your program in a file named awkprof.out. (You can change the filename with the --profile option.) The execution profile is a "prettyprinted" version of your program, with execution counts listed in the left margin. For example, after running this program: $ pgawk '/bash$/ { nusers++ } > END { print nusers, "users use Bash." }' /etc/passwd 16 users use Bash. the execution profile looks like this: # gawk profile, created Mon Nov 1 14:34:38 2004 # Rule(s) 35 /bash$/ { # 16 16 nusers++ } # END block(s) END { 1 print nusers, "users use Bash." } If sent SIGUSR1, pgawk prints the profile and an awk function call stack trace, and then keeps going. Multiple SIGUSR1 signals may be sent; the profile and trace will be printed each time. This facility is useful if your awk program appears to be looping and you want to see if something unexpected is being executed. If sent SIGHUP, pgawk prints the profile and stack trace, and then exits. 11.8.3. File InclusionThe igawk program provides a file-inclusion facility for gawk. You invoke it the same way you do gawk: it passes all command line arguments on to gawk. However, igawk processes source files and command-line programs for special statements of the form: @include file.awk Such files are searched for along the list of directories specified by the AWKPATH environment variable. When found, the @include line is replaced with the text of the corresponding file. Included files may themselves include other files with @include. The combination of the AWKPATH environment variable and igawk makes it easy to have and use libraries of awk functions. 11.8.4. InternationalizationYou can internationalize your programs if you use gawk. This consists of choosing a text domain for your program, marking strings that are to be translated, and, if necessary, using the bindtextdomain( ), dcgettext( ), and dcngettext( ) functions. Localizing your program consists of extracting the marked strings, creating translations, and compiling and installing the translations in the proper place. Full details are given in Effective awk Programming (O'Reilly). The internationalization features in gawk use GNU gettext. You may need to install the GNU gettext tools to create translations if your system doesn't already have them. Here is a very brief outline of the steps involved:
That's it! gawk will automatically find and use the translated messages, if they exist. |