O'Reilly logo

Unix in a Nutshell, 4th Edition by Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Gawk-Specific Features

This section describes features unique to gawk .

Coprocesses and Sockets

gawk 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:

protocol

One of tcp, udp, or raw, for TCP, UDP, or raw IP sockets, respectively. Note: raw is currently reserved but unsupported.

lport

The local TCP or UPD port number to use. Use 0 to let the operating system pick a port.

hostname

The name or IP address of the remote host to connect to.

rport

The port (application) on the remote host to connect to. A service name (e.g., tftp) is looked up using the C getservbyname() function.

Profiling

When gawk is built and installed, a separate program named pgawk (profilinggawk) is built and installed with it. The two programs behave identically; however, pgawk runs more slowly since 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required