home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gawk-2.15.5-bin.lha
/
info
/
gawk.info-6
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-07-11
|
49KB
|
906 lines
This is Info file gawk.info, produced by Makeinfo-1.55 from the input
file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
This file documents `awk', a program that you can use to select
particular records in a file and perform operations upon them.
This is Edition 0.15 of `The GAWK Manual',
for the 2.15 version of the GNU implementation
of AWK.
Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be stated in a
translation approved by the Foundation.
File: gawk.info, Node: I/O Functions, Next: Time Functions, Prev: String Functions, Up: Built-in
Built-in Functions for Input/Output
===================================
`close(FILENAME)'
Close the file FILENAME, for input or output. The argument may
alternatively be a shell command that was used for redirecting to
or from a pipe; then the pipe is closed.
*Note Closing Input Files and Pipes: Close Input, regarding closing
input files and pipes. *Note Closing Output Files and Pipes:
Close Output, regarding closing output files and pipes.
`system(COMMAND)'
The system function allows the user to execute operating system
commands and then return to the `awk' program. The `system'
function executes the command given by the string COMMAND. It
returns, as its value, the status returned by the command that was
executed.
For example, if the following fragment of code is put in your `awk'
program:
END {
system("mail -s 'awk run done' operator < /dev/null")
}
the system operator will be sent mail when the `awk' program
finishes processing input and begins its end-of-input processing.
Note that much the same result can be obtained by redirecting
`print' or `printf' into a pipe. However, if your `awk' program
is interactive, `system' is useful for cranking up large
self-contained programs, such as a shell or an editor.
Some operating systems cannot implement the `system' function.
`system' causes a fatal error if it is not supported.
Controlling Output Buffering with `system'
------------------------------------------
Many utility programs will "buffer" their output; they save
information to be written to a disk file or terminal in memory, until
there is enough to be written in one operation. This is often more
efficient than writing every little bit of information as soon as it is
ready. However, sometimes it is necessary to force a program to
"flush" its buffers; that is, write the information to its destination,
even if a buffer is not full. You can do this from your `awk' program
by calling `system' with a null string as its argument:
system("") # flush output
`gawk' treats this use of the `system' function as a special case, and
is smart enough not to run a shell (or other command interpreter) with
the empty command. Therefore, with `gawk', this idiom is not only
useful, it is efficient. While this idiom should work with other `awk'
implementations, it will not necessarily avoid starting an unnecessary
shell.
File: gawk.info, Node: Time Functions, Prev: I/O Functions, Up: Built-in
Functions for Dealing with Time Stamps
======================================
A common use for `awk' programs is the processing of log files. Log
files often contain time stamp information, indicating when a
particular log record was written. Many programs log their time stamp
in the form returned by the `time' system call, which is the number of
seconds since a particular epoch. On POSIX systems, it is the number
of seconds since Midnight, January 1, 1970, UTC.
In order to make it easier to process such log files, and to easily
produce useful reports, `gawk' provides two functions for working with
time stamps. Both of these are `gawk' extensions; they are not
specified in the POSIX standard, nor are they in any other known version
of `awk'.
`systime()'
This function returns the current time as the number of seconds
since the system epoch. On POSIX systems, this is the number of
seconds since Midnight, January 1, 1970, UTC. It may be a
different number on other systems.
`strftime(FORMAT, TIMESTAMP)'
This function returns a string. It is similar to the function of
the same name in the ANSI C standard library. The time specified
by TIMESTAMP is used to produce a string, based on the contents of
the FORMAT string.
The `systime' function allows you to compare a time stamp from a log
file with the current time of day. In particular, it is easy to
determine how long ago a particular record was logged. It also allows
you to produce log records using the "seconds since the epoch" format.
The `strftime' function allows you to easily turn a time stamp into
human-readable information. It is similar in nature to the `sprintf'
function, copying non-format specification characters verbatim to the
returned string, and substituting date and time values for format
specifications in the FORMAT string. If no TIMESTAMP argument is
supplied, `gawk' will use the current time of day as the time stamp.
`strftime' is guaranteed by the ANSI C standard to support the
following date format specifications:
The locale's abbreviated weekday name.
The locale's full weekday name.
The locale's abbreviated month name.
The locale's full month name.
The locale's "appropriate" date and time representation.
The day of the month as a decimal number (01-31).
The hour (24-hour clock) as a decimal number (00-23).
The hour (12-hour clock) as a decimal number (01-12).
The day of the year as a decimal number (001-366).
The month as a decimal number (01-12).
The minute as a decimal number (00-59).
The locale's equivalent of the AM/PM designations associated with
a 12-hour clock.
The second as a decimal number (00-61). (Occasionally there are
minutes in a year with one or two leap seconds, which is why the
seconds can go from 0 all the way to 61.)
The week number of the year (the first Sunday as the first day of
week 1) as a decimal number (00-53).
The weekday as a decimal number (0-6). Sunday is day 0.
The week number of the year (the first Monday as the first day of
week 1) as a decimal number (00-53).
The locale's "appropriate" date representation.
The locale's "appropriate" time representation.
The year without century as a decimal number (00-99).
The year with century as a decimal number.
The time zone name or abbreviation, or no characters if no time
zone is determinable.
A literal `%'.
If a conversion specifier is not one of the above, the behavior is
undefined. (This is because the ANSI standard for C leaves the
behavior of the C version of `strftime' undefined, and `gawk' will use
the system's version of `strftime' if it's there. Typically, the
conversion specifier will either not appear in the returned string, or
it will appear literally.)
Informally, a "locale" is the geographic place in which a program is
meant to run. For example, a common way to abbreviate the date
September 4, 1991 in the United States would be "9/4/91". In many
countries in Europe, however, it would be abbreviated "4.9.91". Thus,
the `%x' specification in a `"US"' locale might produce `9/4/91', while
in a `"EUROPE"' locale, it might produce `4.9.91'. The ANSI C standard
defines a default `"C"' locale, which is an environment that is typical
of what most C programmers are used to.
A public-domain C v