2012-12-22 10:35:39 -05:00
|
|
|
.de EX
|
|
|
|
.nf
|
|
|
|
.ft CW
|
|
|
|
..
|
|
|
|
.de EE
|
|
|
|
.br
|
|
|
|
.fi
|
|
|
|
.ft 1
|
|
|
|
..
|
|
|
|
.TH AWK 1
|
|
|
|
.CT 1 files prog_other
|
|
|
|
.SH NAME
|
|
|
|
awk \- pattern-directed scanning and processing language
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B awk
|
|
|
|
[
|
|
|
|
.BI \-F
|
|
|
|
.I fs
|
|
|
|
]
|
|
|
|
[
|
|
|
|
.BI \-v
|
|
|
|
.I var=value
|
|
|
|
]
|
|
|
|
[
|
|
|
|
.I 'prog'
|
|
|
|
|
|
|
|
|
.BI \-f
|
|
|
|
.I progfile
|
|
|
|
]
|
|
|
|
[
|
|
|
|
.I file ...
|
|
|
|
]
|
|
|
|
.SH DESCRIPTION
|
|
|
|
.I Awk
|
|
|
|
scans each input
|
|
|
|
.I file
|
|
|
|
for lines that match any of a set of patterns specified literally in
|
2018-08-22 13:40:26 -04:00
|
|
|
.I prog
|
2012-12-22 10:35:39 -05:00
|
|
|
or in one or more files
|
|
|
|
specified as
|
|
|
|
.B \-f
|
|
|
|
.IR progfile .
|
|
|
|
With each pattern
|
|
|
|
there can be an associated action that will be performed
|
|
|
|
when a line of a
|
|
|
|
.I file
|
|
|
|
matches the pattern.
|
|
|
|
Each line is matched against the
|
|
|
|
pattern portion of every pattern-action statement;
|
|
|
|
the associated action is performed for each matched pattern.
|
|
|
|
The file name
|
|
|
|
.B \-
|
|
|
|
means the standard input.
|
|
|
|
Any
|
2018-08-22 13:40:26 -04:00
|
|
|
.I file
|
2012-12-22 10:35:39 -05:00
|
|
|
of the form
|
|
|
|
.I var=value
|
|
|
|
is treated as an assignment, not a filename,
|
|
|
|
and is executed at the time it would have been opened if it were a filename.
|
|
|
|
The option
|
|
|
|
.B \-v
|
|
|
|
followed by
|
|
|
|
.I var=value
|
|
|
|
is an assignment to be done before
|
|
|
|
.I prog
|
|
|
|
is executed;
|
|
|
|
any number of
|
|
|
|
.B \-v
|
|
|
|
options may be present.
|
|
|
|
The
|
|
|
|
.B \-F
|
2018-08-22 13:40:26 -04:00
|
|
|
.I fs
|
2012-12-22 10:35:39 -05:00
|
|
|
option defines the input field separator to be the regular expression
|
2018-08-22 13:40:26 -04:00
|
|
|
.IR fs .
|
2012-12-22 10:35:39 -05:00
|
|
|
.PP
|
|
|
|
An input line is normally made up of fields separated by white space,
|
2018-08-22 13:40:26 -04:00
|
|
|
or by the regular expression
|
2012-12-22 10:35:39 -05:00
|
|
|
.BR FS .
|
|
|
|
The fields are denoted
|
|
|
|
.BR $1 ,
|
|
|
|
.BR $2 ,
|
|
|
|
\&..., while
|
|
|
|
.B $0
|
|
|
|
refers to the entire line.
|
|
|
|
If
|
|
|
|
.BR FS
|
|
|
|
is null, the input line is split into one field per character.
|
|
|
|
.PP
|
2018-08-22 13:40:26 -04:00
|
|
|
A pattern-action statement has the form:
|
2012-12-22 10:35:39 -05:00
|
|
|
.IP
|
|
|
|
.IB pattern " { " action " }
|
|
|
|
.PP
|
|
|
|
A missing
|
|
|
|
.BI { " action " }
|
|
|
|
means print the line;
|
|
|
|
a missing pattern always matches.
|
|
|
|
Pattern-action statements are separated by newlines or semicolons.
|
|
|
|
.PP
|
|
|
|
An action is a sequence of statements.
|
|
|
|
A statement can be one of the following:
|
|
|
|
.PP
|
|
|
|
.EX
|
2018-08-22 13:40:26 -04:00
|
|
|
.ta \w'\f(CWdelete array[expression]\fR'u
|
2012-12-22 10:35:39 -05:00
|
|
|
.RS
|
|
|
|
.nf
|
|
|
|
.ft CW
|
|
|
|
if(\fI expression \fP)\fI statement \fP\fR[ \fPelse\fI statement \fP\fR]\fP
|
|
|
|
while(\fI expression \fP)\fI statement\fP
|
|
|
|
for(\fI expression \fP;\fI expression \fP;\fI expression \fP)\fI statement\fP
|
|
|
|
for(\fI var \fPin\fI array \fP)\fI statement\fP
|
|
|
|
do\fI statement \fPwhile(\fI expression \fP)
|
|
|
|
break
|
|
|
|
continue
|
|
|
|
{\fR [\fP\fI statement ... \fP\fR] \fP}
|
|
|
|
\fIexpression\fP #\fR commonly\fP\fI var = expression\fP
|
|
|
|
print\fR [ \fP\fIexpression-list \fP\fR] \fP\fR[ \fP>\fI expression \fP\fR]\fP
|
|
|
|
printf\fI format \fP\fR[ \fP,\fI expression-list \fP\fR] \fP\fR[ \fP>\fI expression \fP\fR]\fP
|
|
|
|
return\fR [ \fP\fIexpression \fP\fR]\fP
|
|
|
|
next #\fR skip remaining patterns on this input line\fP
|
|
|
|
nextfile #\fR skip rest of this file, open next, start at top\fP
|
|
|
|
delete\fI array\fP[\fI expression \fP] #\fR delete an array element\fP
|
|
|
|
delete\fI array\fP #\fR delete all elements of array\fP
|
|
|
|
exit\fR [ \fP\fIexpression \fP\fR]\fP #\fR exit immediately; status is \fP\fIexpression\fP
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.EE
|
|
|
|
.DT
|
|
|
|
.PP
|
|
|
|
Statements are terminated by
|
|
|
|
semicolons, newlines or right braces.
|
|
|
|
An empty
|
|
|
|
.I expression-list
|
|
|
|
stands for
|
|
|
|
.BR $0 .
|
|
|
|
String constants are quoted \&\f(CW"\ "\fR,
|
|
|
|
with the usual C escapes recognized within.
|
|
|
|
Expressions take on string or numeric values as appropriate,
|
|
|
|
and are built using the operators
|
|
|
|
.B + \- * / % ^
|
|
|
|
(exponentiation), and concatenation (indicated by white space).
|
|
|
|
The operators
|
|
|
|
.B
|
|
|
|
! ++ \-\- += \-= *= /= %= ^= > >= < <= == != ?:
|
|
|
|
are also available in expressions.
|
|
|
|
Variables may be scalars, array elements
|
|
|
|
(denoted
|
2018-08-22 13:40:26 -04:00
|
|
|
.IB x [ i ] \fR)
|
2012-12-22 10:35:39 -05:00
|
|
|
or fields.
|
|
|
|
Variables are initialized to the null string.
|
|
|
|
Array subscripts may be any string,
|
|
|
|
not necessarily numeric;
|
|
|
|
this allows for a form of associative memory.
|
|
|
|
Multiple subscripts such as
|
|
|
|
.B [i,j,k]
|
|
|
|
are permitted; the constituents are concatenated,
|
|
|
|
separated by the value of
|
|
|
|
.BR SUBSEP .
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.B print
|
|
|
|
statement prints its arguments on the standard output
|
|
|
|
(or on a file if
|
2018-08-22 13:40:26 -04:00
|
|
|
.BI > " file
|
2012-12-22 10:35:39 -05:00
|
|
|
or
|
2018-08-22 13:40:26 -04:00
|
|
|
.BI >> " file
|
2012-12-22 10:35:39 -05:00
|
|
|
is present or on a pipe if
|
2018-08-22 13:40:26 -04:00
|
|
|
.BI | " cmd
|
2012-12-22 10:35:39 -05:00
|
|
|
is present), separated by the current output field separator,
|
|
|
|
and terminated by the output record separator.
|
|
|
|
.I file
|
|
|
|
and
|
|
|
|
.I cmd
|
|
|
|
may be literal names or parenthesized expressions;
|
|
|
|
identical string values in different statements denote
|
|
|
|
the same open file.
|
|
|
|
The
|
|
|
|
.B printf
|
2018-08-22 13:40:26 -04:00
|
|
|
statement formats its expression list according to the
|
|
|
|
.I format
|
2012-12-22 10:35:39 -05:00
|
|
|
(see
|
2018-08-22 13:40:26 -04:00
|
|
|
.IR printf (3)).
|
2012-12-22 10:35:39 -05:00
|
|
|
The built-in function
|
|
|
|
.BI close( expr )
|
|
|
|
closes the file or pipe
|
|
|
|
.IR expr .
|
|
|
|
The built-in function
|
|
|
|
.BI fflush( expr )
|
|
|
|
flushes any buffered output for the file or pipe
|
|
|
|
.IR expr .
|
|
|
|
.PP
|
|
|
|
The mathematical functions
|
2018-08-22 13:40:26 -04:00
|
|
|
.BR atan2 ,
|
|
|
|
.BR cos ,
|
2012-12-22 10:35:39 -05:00
|
|
|
.BR exp ,
|
|
|
|
.BR log ,
|
|
|
|
.BR sin ,
|
|
|
|
and
|
2018-08-22 13:40:26 -04:00
|
|
|
.B sqrt
|
2012-12-22 10:35:39 -05:00
|
|
|
are built in.
|
|
|
|
Other built-in functions:
|
|
|
|
.TF length
|
|
|
|
.TP
|
|
|
|
.B length
|
|
|
|
the length of its argument
|
|
|
|
taken as a string,
|
2018-08-22 13:40:26 -04:00
|
|
|
number of elements in an array for an array argument,
|
|
|
|
or length of
|
2012-12-22 10:35:39 -05:00
|
|
|
.B $0
|
|
|
|
if no argument.
|
|
|
|
.TP
|
|
|
|
.B rand
|
|
|
|
random number on (0,1)
|
|
|
|
.TP
|
|
|
|
.B srand
|
|
|
|
sets seed for
|
|
|
|
.B rand
|
|
|
|
and returns the previous seed.
|
|
|
|
.TP
|
|
|
|
.B int
|
|
|
|
truncates to an integer value
|
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
\fBsubstr(\fIs\fB, \fIm\fR [\fB, \fIn\^\fR]\fB)\fR
|
2012-12-22 10:35:39 -05:00
|
|
|
the
|
|
|
|
.IR n -character
|
|
|
|
substring of
|
|
|
|
.I s
|
|
|
|
that begins at position
|
2018-08-22 13:40:26 -04:00
|
|
|
.I m
|
2012-12-22 10:35:39 -05:00
|
|
|
counted from 1.
|
2018-08-22 13:40:26 -04:00
|
|
|
If no
|
|
|
|
.IR m ,
|
|
|
|
use the rest of the string
|
|
|
|
.I
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
|
|
|
.BI index( s , " t" )
|
|
|
|
the position in
|
|
|
|
.I s
|
|
|
|
where the string
|
|
|
|
.I t
|
|
|
|
occurs, or 0 if it does not.
|
|
|
|
.TP
|
|
|
|
.BI match( s , " r" )
|
|
|
|
the position in
|
|
|
|
.I s
|
|
|
|
where the regular expression
|
|
|
|
.I r
|
|
|
|
occurs, or 0 if it does not.
|
|
|
|
The variables
|
|
|
|
.B RSTART
|
|
|
|
and
|
|
|
|
.B RLENGTH
|
|
|
|
are set to the position and length of the matched string.
|
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
\fBsplit(\fIs\fB, \fIa \fR[\fB, \fIfs\^\fR]\fB)\fR
|
2012-12-22 10:35:39 -05:00
|
|
|
splits the string
|
|
|
|
.I s
|
|
|
|
into array elements
|
2018-08-22 13:40:26 -04:00
|
|
|
.IB a [1] \fR,
|
|
|
|
.IB a [2] \fR,
|
2012-12-22 10:35:39 -05:00
|
|
|
\&...,
|
2018-08-22 13:40:26 -04:00
|
|
|
.IB a [ n ] \fR,
|
2012-12-22 10:35:39 -05:00
|
|
|
and returns
|
|
|
|
.IR n .
|
|
|
|
The separation is done with the regular expression
|
|
|
|
.I fs
|
|
|
|
or with the field separator
|
|
|
|
.B FS
|
|
|
|
if
|
|
|
|
.I fs
|
|
|
|
is not given.
|
|
|
|
An empty string as field separator splits the string
|
|
|
|
into one array element per character.
|
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
\fBsub(\fIr\fB, \fIt \fR[, \fIs\^\fR]\fB)
|
2012-12-22 10:35:39 -05:00
|
|
|
substitutes
|
|
|
|
.I t
|
|
|
|
for the first occurrence of the regular expression
|
|
|
|
.I r
|
|
|
|
in the string
|
|
|
|
.IR s .
|
|
|
|
If
|
|
|
|
.I s
|
|
|
|
is not given,
|
|
|
|
.B $0
|
|
|
|
is used.
|
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
\fBgsub(\fIr\fB, \fIt \fR[, \fIs\^\fR]\fB)
|
2012-12-22 10:35:39 -05:00
|
|
|
same as
|
|
|
|
.B sub
|
|
|
|
except that all occurrences of the regular expression
|
|
|
|
are replaced;
|
|
|
|
.B sub
|
|
|
|
and
|
|
|
|
.B gsub
|
|
|
|
return the number of replacements.
|
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
.BI sprintf( fmt , " expr" , " ...\fB)
|
2012-12-22 10:35:39 -05:00
|
|
|
the string resulting from formatting
|
|
|
|
.I expr ...
|
|
|
|
according to the
|
|
|
|
.IR printf (3)
|
|
|
|
format
|
2018-08-22 13:40:26 -04:00
|
|
|
.IR fmt .
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
|
|
|
.BI system( cmd )
|
|
|
|
executes
|
|
|
|
.I cmd
|
2018-08-22 13:40:26 -04:00
|
|
|
and returns its exit status. This will be \-1 upon error,
|
|
|
|
.IR cmd 's
|
|
|
|
exit status upon a normal exit,
|
|
|
|
256 +
|
|
|
|
.I sig
|
|
|
|
upon death-by-signal, where
|
|
|
|
.I sig
|
|
|
|
is the number of the murdering signal,
|
|
|
|
or 512 +
|
|
|
|
.I sig
|
|
|
|
if there was a core dump.
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
|
|
|
.BI tolower( str )
|
|
|
|
returns a copy of
|
|
|
|
.I str
|
|
|
|
with all upper-case characters translated to their
|
|
|
|
corresponding lower-case equivalents.
|
|
|
|
.TP
|
|
|
|
.BI toupper( str )
|
|
|
|
returns a copy of
|
|
|
|
.I str
|
|
|
|
with all lower-case characters translated to their
|
|
|
|
corresponding upper-case equivalents.
|
|
|
|
.PD
|
|
|
|
.PP
|
|
|
|
The ``function''
|
|
|
|
.B getline
|
|
|
|
sets
|
|
|
|
.B $0
|
|
|
|
to the next input record from the current input file;
|
|
|
|
.B getline
|
2018-08-22 13:40:26 -04:00
|
|
|
.BI < " file
|
2012-12-22 10:35:39 -05:00
|
|
|
sets
|
|
|
|
.B $0
|
|
|
|
to the next record from
|
|
|
|
.IR file .
|
|
|
|
.B getline
|
|
|
|
.I x
|
|
|
|
sets variable
|
|
|
|
.I x
|
|
|
|
instead.
|
|
|
|
Finally,
|
|
|
|
.IB cmd " | getline
|
|
|
|
pipes the output of
|
|
|
|
.I cmd
|
|
|
|
into
|
|
|
|
.BR getline ;
|
|
|
|
each call of
|
|
|
|
.B getline
|
|
|
|
returns the next line of output from
|
|
|
|
.IR cmd .
|
|
|
|
In all cases,
|
|
|
|
.B getline
|
|
|
|
returns 1 for a successful input,
|
|
|
|
0 for end of file, and \-1 for an error.
|
|
|
|
.PP
|
|
|
|
Patterns are arbitrary Boolean combinations
|
|
|
|
(with
|
|
|
|
.BR "! || &&" )
|
|
|
|
of regular expressions and
|
|
|
|
relational expressions.
|
|
|
|
Regular expressions are as in
|
|
|
|
.IR egrep ;
|
|
|
|
see
|
|
|
|
.IR grep (1).
|
|
|
|
Isolated regular expressions
|
|
|
|
in a pattern apply to the entire line.
|
|
|
|
Regular expressions may also occur in
|
|
|
|
relational expressions, using the operators
|
2018-08-22 13:40:26 -04:00
|
|
|
.B ~
|
2012-12-22 10:35:39 -05:00
|
|
|
and
|
|
|
|
.BR !~ .
|
|
|
|
.BI / re /
|
|
|
|
is a constant regular expression;
|
|
|
|
any string (constant or variable) may be used
|
|
|
|
as a regular expression, except in the position of an isolated regular expression
|
|
|
|
in a pattern.
|
|
|
|
.PP
|
|
|
|
A pattern may consist of two patterns separated by a comma;
|
|
|
|
in this case, the action is performed for all lines
|
|
|
|
from an occurrence of the first pattern
|
|
|
|
though an occurrence of the second.
|
|
|
|
.PP
|
|
|
|
A relational expression is one of the following:
|
|
|
|
.IP
|
|
|
|
.I expression matchop regular-expression
|
|
|
|
.br
|
|
|
|
.I expression relop expression
|
|
|
|
.br
|
|
|
|
.IB expression " in " array-name
|
|
|
|
.br
|
|
|
|
.BI ( expr , expr,... ") in " array-name
|
|
|
|
.PP
|
2018-08-22 13:40:26 -04:00
|
|
|
where a
|
|
|
|
.I relop
|
|
|
|
is any of the six relational operators in C,
|
|
|
|
and a
|
|
|
|
.I matchop
|
|
|
|
is either
|
2012-12-22 10:35:39 -05:00
|
|
|
.B ~
|
|
|
|
(matches)
|
|
|
|
or
|
|
|
|
.B !~
|
|
|
|
(does not match).
|
|
|
|
A conditional is an arithmetic expression,
|
|
|
|
a relational expression,
|
|
|
|
or a Boolean combination
|
|
|
|
of these.
|
|
|
|
.PP
|
|
|
|
The special patterns
|
|
|
|
.B BEGIN
|
|
|
|
and
|
|
|
|
.B END
|
|
|
|
may be used to capture control before the first input line is read
|
|
|
|
and after the last.
|
|
|
|
.B BEGIN
|
|
|
|
and
|
|
|
|
.B END
|
|
|
|
do not combine with other patterns.
|
2018-08-22 13:40:26 -04:00
|
|
|
They may appear multiple times in a program and execute
|
|
|
|
in the order they are read by
|
|
|
|
.IR awk .
|
2012-12-22 10:35:39 -05:00
|
|
|
.PP
|
|
|
|
Variable names with special meanings:
|
|
|
|
.TF FILENAME
|
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
.B ARGC
|
|
|
|
argument count, assignable.
|
|
|
|
.TP
|
|
|
|
.B ARGV
|
|
|
|
argument array, assignable;
|
|
|
|
non-null members are taken as filenames.
|
|
|
|
.TP
|
2012-12-22 10:35:39 -05:00
|
|
|
.B CONVFMT
|
|
|
|
conversion format used when converting numbers
|
|
|
|
(default
|
2018-08-22 13:40:26 -04:00
|
|
|
.BR "%.6g" ).
|
|
|
|
.TP
|
|
|
|
.B ENVIRON
|
|
|
|
array of environment variables; subscripts are names.
|
|
|
|
.TP
|
|
|
|
.B FILENAME
|
|
|
|
the name of the current input file.
|
|
|
|
.TP
|
|
|
|
.B FNR
|
|
|
|
ordinal number of the current record in the current file.
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
|
|
|
.B FS
|
|
|
|
regular expression used to separate fields; also settable
|
|
|
|
by option
|
2018-08-22 13:40:26 -04:00
|
|
|
.BI \-F fs\fR.
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
|
|
|
.BR NF
|
2018-08-22 13:40:26 -04:00
|
|
|
number of fields in the current record.
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
|
|
|
.B NR
|
2018-08-22 13:40:26 -04:00
|
|
|
ordinal number of the current record.
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
.B OFMT
|
|
|
|
output format for numbers (default
|
|
|
|
.BR "%.6g" ).
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
|
|
|
.B OFS
|
2018-08-22 13:40:26 -04:00
|
|
|
output field separator (default space).
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
|
|
|
.B ORS
|
2018-08-22 13:40:26 -04:00
|
|
|
output record separator (default newline).
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
.B RLENGTH
|
|
|
|
the length of a string matched by
|
|
|
|
.BR match .
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
.B RS
|
|
|
|
input record separator (default newline).
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
.B RSTART
|
|
|
|
the start position of a string matched by
|
|
|
|
.BR match .
|
2012-12-22 10:35:39 -05:00
|
|
|
.TP
|
2018-08-22 13:40:26 -04:00
|
|
|
.B SUBSEP
|
|
|
|
separates multiple subscripts (default 034).
|
2012-12-22 10:35:39 -05:00
|
|
|
.PD
|
|
|
|
.PP
|
|
|
|
Functions may be defined (at the position of a pattern-action statement) thus:
|
|
|
|
.IP
|
|
|
|
.B
|
|
|
|
function foo(a, b, c) { ...; return x }
|
|
|
|
.PP
|
|
|
|
Parameters are passed by value if scalar and by reference if array name;
|
|
|
|
functions may be called recursively.
|
|
|
|
Parameters are local to the function; all other variables are global.
|
|
|
|
Thus local variables may be created by providing excess parameters in
|
|
|
|
the function definition.
|
|
|
|
.SH EXAMPLES
|
|
|
|
.TP
|
|
|
|
.EX
|
|
|
|
length($0) > 72
|
|
|
|
.EE
|
|
|
|
Print lines longer than 72 characters.
|
|
|
|
.TP
|
|
|
|
.EX
|
|
|
|
{ print $2, $1 }
|
|
|
|
.EE
|
|
|
|
Print first two fields in opposite order.
|
|
|
|
.PP
|
|
|
|
.EX
|
|
|
|
BEGIN { FS = ",[ \et]*|[ \et]+" }
|
|
|
|
{ print $2, $1 }
|
|
|
|
.EE
|
|
|
|
.ns
|
|
|
|
.IP
|
2018-08-22 13:40:26 -04:00
|
|
|
Same, with input fields separated by comma and/or spaces and tabs.
|
2012-12-22 10:35:39 -05:00
|
|
|
.PP
|
|
|
|
.EX
|
|
|
|
.nf
|
|
|
|
{ s += $1 }
|
|
|
|
END { print "sum is", s, " average is", s/NR }
|
|
|
|
.fi
|
|
|
|
.EE
|
|
|
|
.ns
|
|
|
|
.IP
|
|
|
|
Add up first column, print sum and average.
|
|
|
|
.TP
|
|
|
|
.EX
|
|
|
|
/start/, /stop/
|
|
|
|
.EE
|
|
|
|
Print all lines between start/stop pairs.
|
|
|
|
.PP
|
|
|
|
.EX
|
|
|
|
.nf
|
|
|
|
BEGIN { # Simulate echo(1)
|
|
|
|
for (i = 1; i < ARGC; i++) printf "%s ", ARGV[i]
|
|
|
|
printf "\en"
|
|
|
|
exit }
|
|
|
|
.fi
|
|
|
|
.EE
|
|
|
|
.SH SEE ALSO
|
2018-08-22 13:40:26 -04:00
|
|
|
.IR grep (1),
|
2012-12-22 10:35:39 -05:00
|
|
|
.IR lex (1),
|
|
|
|
.IR sed (1)
|
|
|
|
.br
|
|
|
|
A. V. Aho, B. W. Kernighan, P. J. Weinberger,
|
2018-08-22 13:40:26 -04:00
|
|
|
.IR "The AWK Programming Language" ,
|
|
|
|
Addison-Wesley, 1988. ISBN 0-201-07981-X.
|
2012-12-22 10:35:39 -05:00
|
|
|
.SH BUGS
|
|
|
|
There are no explicit conversions between numbers and strings.
|
|
|
|
To force an expression to be treated as a number add 0 to it;
|
|
|
|
to force it to be treated as a string concatenate
|
|
|
|
\&\f(CW""\fP to it.
|
|
|
|
.br
|
|
|
|
The scope rules for variables in functions are a botch;
|
|
|
|
the syntax is worse.
|
2018-08-22 13:40:26 -04:00
|
|
|
.br
|
|
|
|
POSIX-standard interval expressions in regular expressions are not supported.
|
|
|
|
.br
|
|
|
|
Only eight-bit characters sets are handled correctly.
|