xref: /openbsd-src/usr.bin/awk/awk.1 (revision 52752bf43baeb94ac1e2ae081589f8ecc124cdf0)
1*52752bf4Snaddy.\"	$OpenBSD: awk.1,v 1.71 2024/12/25 13:44:22 naddy Exp $
2116aad93Sjmc.\"
3116aad93Sjmc.\" Copyright (C) Lucent Technologies 1997
4116aad93Sjmc.\" All Rights Reserved
5116aad93Sjmc.\"
6116aad93Sjmc.\" Permission to use, copy, modify, and distribute this software and
7116aad93Sjmc.\" its documentation for any purpose and without fee is hereby
8116aad93Sjmc.\" granted, provided that the above copyright notice appear in all
9116aad93Sjmc.\" copies and that both that the copyright notice and this
10116aad93Sjmc.\" permission notice and warranty disclaimer appear in supporting
11116aad93Sjmc.\" documentation, and that the name Lucent Technologies or any of
12116aad93Sjmc.\" its entities not be used in advertising or publicity pertaining
13116aad93Sjmc.\" to distribution of the software without specific, written prior
14116aad93Sjmc.\" permission.
15116aad93Sjmc.\"
16116aad93Sjmc.\" LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17116aad93Sjmc.\" INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
18116aad93Sjmc.\" IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
19116aad93Sjmc.\" SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20116aad93Sjmc.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
21116aad93Sjmc.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22116aad93Sjmc.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
23116aad93Sjmc.\" THIS SOFTWARE.
24116aad93Sjmc.\"
25*52752bf4Snaddy.Dd $Mdocdate: December 25 2024 $
2680343d32Saaron.Dt AWK 1
2780343d32Saaron.Os
2880343d32Saaron.Sh NAME
2980343d32Saaron.Nm awk
3080343d32Saaron.Nd pattern-directed scanning and processing language
3180343d32Saaron.Sh SYNOPSIS
3280343d32Saaron.Nm awk
3380343d32Saaron.Op Fl safe
34daef5724Sjmc.Op Fl V
35daef5724Sjmc.Op Fl d Ns Op Ar n
36a886e62eSmillert.Op Fl F Ar fs | Fl -csv
37f24d0cbbSschwarze.Op Fl v Ar var Ns = Ns Ar value
38e624cbe1Sjmc.Op Ar prog | Fl f Ar progfile
3980343d32Saaron.Ar
4080343d32Saaron.Sh DESCRIPTION
4180343d32Saaron.Nm
426ab05f83Stholoscans each input
4380343d32Saaron.Ar file
446ab05f83Stholofor lines that match any of a set of patterns specified literally in
4580343d32Saaron.Ar prog
46daef5724Sjmcor in one or more files specified as
4780343d32Saaron.Fl f Ar progfile .
48daef5724SjmcWith each pattern there can be an associated action that will be performed
496ab05f83Stholowhen a line of a
5080343d32Saaron.Ar file
516ab05f83Stholomatches the pattern.
526ab05f83StholoEach line is matched against the
536ab05f83Stholopattern portion of every pattern-action statement;
546ab05f83Stholothe associated action is performed for each matched pattern.
556ab05f83StholoThe file name
56daef5724Sjmc.Sq -
576ab05f83Stholomeans the standard input.
586ab05f83StholoAny
5980343d32Saaron.Ar file
606ab05f83Stholoof the form
61daef5724Sjmc.Ar var Ns = Ns Ar value
626ab05f83Stholois treated as an assignment, not a filename,
636ab05f83Stholoand is executed at the time it would have been opened if it were a filename.
64daef5724Sjmc.Pp
65daef5724SjmcThe options are as follows:
6644123e9cSjmc.Bl -tag -width "-safe "
67a886e62eSmillert.It Fl -csv
68a886e62eSmillertProcess records using the (more or less) standard comma-separated values
69a886e62eSmillert.Pq CSV
70a886e62eSmillertformat instead of the input field separator.
71a886e62eSmillertWhen the
72a886e62eSmillert.Fl -csv
73a886e62eSmillertoption is specified, attempts to change the input field separator
74a886e62eSmillertor record separator are ignored.
75daef5724Sjmc.It Fl d Ns Op Ar n
76daef5724SjmcDebug mode.
77daef5724SjmcSet debug level to
78daef5724Sjmc.Ar n ,
79daef5724Sjmcor 1 if
80daef5724Sjmc.Ar n
81daef5724Sjmcis not specified.
82daef5724SjmcA value greater than 1 causes
83daef5724Sjmc.Nm
84daef5724Sjmcto dump core on fatal errors.
85daef5724Sjmc.It Fl F Ar fs
86daef5724SjmcDefine the input field separator to be the regular expression
8780343d32Saaron.Ar fs .
88bbd8a5e9Sjmc.It Fl f Ar progfile
89daef5724SjmcRead program code from the specified file
90bbd8a5e9Sjmc.Ar progfile
91daef5724Sjmcinstead of from the command line.
92daef5724Sjmc.It Fl safe
93daef5724SjmcDisable file output
941e60b1a3Sjmc.Pf ( Ic print No > ,
951e60b1a3Sjmc.Ic print No >> ) ,
9680343d32Saaronprocess creation
9780343d32Saaron.Po
981e60b1a3Sjmc.Ar cmd | Ic getline ,
998580efa1Sjmc.Ic print | ,
1001e60b1a3Sjmc.Ic system
10180343d32Saaron.Pc
10280343d32Saaronand access to the environment
1031e60b1a3Sjmc.Pf ( Va ENVIRON ;
104e624cbe1Sjmcsee the section on variables below).
1051e60b1a3SjmcThis is a first
106daef5724Sjmc.Pq and not very reliable
107daef5724Sjmcapproximation to a
10880343d32Saaron.Dq safe
10980343d32Saaronversion of
110daef5724Sjmc.Nm .
111daef5724Sjmc.It Fl V
112daef5724SjmcPrint the version number of
113daef5724Sjmc.Nm
114daef5724Sjmcto standard output and exit.
115daef5724Sjmc.It Fl v Ar var Ns = Ns Ar value
116daef5724SjmcAssign
117daef5724Sjmc.Ar value
118daef5724Sjmcto variable
119daef5724Sjmc.Ar var
120daef5724Sjmcbefore
121daef5724Sjmc.Ar prog
122daef5724Sjmcis executed;
123daef5724Sjmcany number of
124daef5724Sjmc.Fl v
125daef5724Sjmcoptions may be present.
126daef5724Sjmc.El
12780343d32Saaron.Pp
128e624cbe1SjmcThe input is normally made up of input lines
129e624cbe1Sjmc.Pq records
130e624cbe1Sjmcseparated by newlines, or by the value of
131e624cbe1Sjmc.Va RS .
132e624cbe1SjmcIf
133e624cbe1Sjmc.Va RS
134e624cbe1Sjmcis null, then any number of blank lines are used as the record separator,
135e624cbe1Sjmcand newlines are used as field separators
136e624cbe1Sjmc(in addition to the value of
137e624cbe1Sjmc.Va FS ) .
138e624cbe1SjmcThis is convenient when working with multi-line records.
139e624cbe1Sjmc.Pp
1406ab05f83StholoAn input line is normally made up of fields separated by whitespace,
14142fb2d3dSmillertor by the value of the field separator
14242fb2d3dSmillert.Va FS
14342fb2d3dSmillertat the time the line is read.
1446ab05f83StholoThe fields are denoted
14580343d32Saaron.Va $1 , $2 , ... ,
14680343d32Saaronwhile
14780343d32Saaron.Va $0
1486ab05f83Stholorefers to the entire line.
14942fb2d3dSmillert.Va FS
15042fb2d3dSmillertmay be set to either a single character or a regular expression.
151d50eda91SjmcAs a special case, if
15242fb2d3dSmillert.Va FS
15342fb2d3dSmillertis a single space
15442fb2d3dSmillert.Pq the default ,
15542fb2d3dSmillertfields will be split by one or more whitespace characters.
1566ab05f83StholoIf
15780343d32Saaron.Va FS
1586ab05f83Stholois null, the input line is split into one field per character.
15980343d32Saaron.Pp
160e624cbe1SjmcNormally, any number of blanks separate fields.
161e624cbe1SjmcIn order to set the field separator to a single blank, use the
162e624cbe1Sjmc.Fl F
163e624cbe1Sjmcoption with a value of
164e624cbe1Sjmc.Sq [\ \&] .
165e624cbe1SjmcIf a field separator of
166e624cbe1Sjmc.Sq t
167e624cbe1Sjmcis specified,
168e624cbe1Sjmc.Nm
169e624cbe1Sjmctreats it as if
170e624cbe1Sjmc.Sq \et
171e624cbe1Sjmchad been specified and uses
172e624cbe1Sjmc.Aq TAB
173e624cbe1Sjmcas the field separator.
174e624cbe1SjmcIn order to use a literal
175e624cbe1Sjmc.Sq t
176e624cbe1Sjmcas the field separator, use the
177e624cbe1Sjmc.Fl F
178e624cbe1Sjmcoption with a value of
179e624cbe1Sjmc.Sq [t] .
18042fb2d3dSmillertThe field separator is usually set via the
18142fb2d3dSmillert.Fl F
18242fb2d3dSmillertoption or from inside a
18342fb2d3dSmillert.Ic BEGIN
18442fb2d3dSmillertblock so that it takes effect before the input is read.
185e624cbe1Sjmc.Pp
186c062391aSmillertA pattern-action statement has the form:
18780343d32Saaron.Pp
18880343d32Saaron.D1 Ar pattern Ic \&{ Ar action Ic \&}
18980343d32Saaron.Pp
1906ab05f83StholoA missing
19180343d32Saaron.Ic \&{ Ar action Ic \&}
1926ab05f83Stholomeans print the line;
1936ab05f83Stholoa missing pattern always matches.
1946ab05f83StholoPattern-action statements are separated by newlines or semicolons.
19580343d32Saaron.Pp
196e624cbe1SjmcNewlines are permitted after a terminating statement or following a comma
197e624cbe1Sjmc.Pq Sq ,\& ,
198e624cbe1Sjmcan open brace
199e624cbe1Sjmc.Pq Sq { ,
200e624cbe1Sjmca logical AND
201e624cbe1Sjmc.Pq Sq && ,
202e624cbe1Sjmca logical OR
203e624cbe1Sjmc.Pq Sq || ,
204e624cbe1Sjmcafter the
205e624cbe1Sjmc.Sq do
206e624cbe1Sjmcor
207e624cbe1Sjmc.Sq else
208e624cbe1Sjmckeywords,
209e624cbe1Sjmcor after the closing parenthesis of an
210e624cbe1Sjmc.Sq if ,
211e624cbe1Sjmc.Sq for ,
212e624cbe1Sjmcor
213e624cbe1Sjmc.Sq while
214e624cbe1Sjmcstatement.
215e624cbe1SjmcAdditionally, a backslash
216e624cbe1Sjmc.Pq Sq \e
217e624cbe1Sjmccan be used to escape a newline between tokens.
218e624cbe1Sjmc.Pp
2196ab05f83StholoAn action is a sequence of statements.
2206ab05f83StholoA statement can be one of the following:
221489d5c95Sjmc.Pp
222489d5c95Sjmc.Bl -tag -width Ds -offset indent -compact
223282b7db2Sschwarze.It Ic if Ar ( expression ) Ar statement Op Ic else Ar statement
224282b7db2Sschwarze.It Ic while Ar ( expression ) Ar statement
225282b7db2Sschwarze.It Ic for Ar ( expression ; expression ; expression ) statement
226282b7db2Sschwarze.It Ic for Ar ( var Ic in Ar array ) statement
227282b7db2Sschwarze.It Ic do Ar statement Ic while Ar ( expression )
228489d5c95Sjmc.It Ic break
229489d5c95Sjmc.It Ic continue
230489d5c95Sjmc.It Xo Ic {
231489d5c95Sjmc.Op Ar statement ...
232489d5c95Sjmc.Ic }
233489d5c95Sjmc.Xc
234489d5c95Sjmc.It Xo Ar expression
235489d5c95Sjmc.No # commonly
236489d5c95Sjmc.Ar var No = Ar expression
237489d5c95Sjmc.Xc
238489d5c95Sjmc.It Xo Ic print
23980343d32Saaron.Op Ar expression-list
2401e60b1a3Sjmc.Op > Ns Ar expression
24180343d32Saaron.Xc
242489d5c95Sjmc.It Xo Ic printf Ar format
24380343d32Saaron.Op Ar ... , expression-list
2441e60b1a3Sjmc.Op > Ns Ar expression
24580343d32Saaron.Xc
246489d5c95Sjmc.It Ic return Op Ar expression
247489d5c95Sjmc.It Xo Ic next
248489d5c95Sjmc.No # skip remaining patterns on this input line
24980343d32Saaron.Xc
250489d5c95Sjmc.It Xo Ic nextfile
251489d5c95Sjmc.No # skip rest of this file, open next, start at top
25280343d32Saaron.Xc
253489d5c95Sjmc.It Xo Ic delete
254489d5c95Sjmc.Sm off
255489d5c95Sjmc.Ar array Ic \&[ Ar expression Ic \&]
256489d5c95Sjmc.Sm on
257489d5c95Sjmc.No # delete an array element
25880343d32Saaron.Xc
259489d5c95Sjmc.It Xo Ic delete Ar array
260489d5c95Sjmc.No # delete all elements of array
26180343d32Saaron.Xc
262489d5c95Sjmc.It Xo Ic exit
26380343d32Saaron.Op Ar expression
2643f582d5fSderaadt.No # exit processing, and perform
2653f582d5fSderaadt.Ic END
2663f582d5fSderaadtprocessing; status is
2673f582d5fSderaadt.Ar expression
26880343d32Saaron.Xc
269489d5c95Sjmc.El
27080343d32Saaron.Pp
2716ab05f83StholoStatements are terminated by
2726ab05f83Stholosemicolons, newlines or right braces.
2736ab05f83StholoAn empty
27480343d32Saaron.Ar expression-list
2756ab05f83Stholostands for
27680343d32Saaron.Ar $0 .
27780343d32SaaronString constants are quoted
27880343d32Saaron.Li \&"" ,
27944123e9cSjmcwith the usual C escapes recognized within
28044123e9cSjmc(see
28144123e9cSjmc.Xr printf 1
28244123e9cSjmcfor a complete list of these).
2836ab05f83StholoExpressions take on string or numeric values as appropriate,
2846ab05f83Stholoand are built using the operators
28580343d32Saaron.Ic + \- * / % ^
28644123e9cSjmc.Pq exponentiation ,
28744123e9cSjmcand concatenation
28844123e9cSjmc.Pq indicated by whitespace .
2896ab05f83StholoThe operators
290daef5724Sjmc.Ic \&! ++ \-\- += \-= *= /= %= ^=
291483fa115Smillert.Ic > >= < <= == != ?\&:
2926ab05f83Stholoare also available in expressions.
2936ab05f83StholoVariables may be scalars, array elements
2946ab05f83Stholo(denoted
29580343d32Saaron.Li x[i] )
2966ab05f83Stholoor fields.
2976ab05f83StholoVariables are initialized to the null string.
2986ab05f83StholoArray subscripts may be any string,
2996ab05f83Stholonot necessarily numeric;
3006ab05f83Stholothis allows for a form of associative memory.
3016ab05f83StholoMultiple subscripts such as
30280343d32Saaron.Li [i,j,k]
3036ab05f83Stholoare permitted; the constituents are concatenated,
3046ab05f83Stholoseparated by the value of
3051e60b1a3Sjmc.Va SUBSEP
3061b628022Sderaadt.Pq see the section on variables below .
30780343d32Saaron.Pp
3086ab05f83StholoThe
30980343d32Saaron.Ic print
3106ab05f83Stholostatement prints its arguments on the standard output
3116ab05f83Stholo(or on a file if
312c062391aSmillert.Pf >\ \& Ar file
3136ab05f83Stholoor
314c062391aSmillert.Pf >>\ \& Ar file
3156ab05f83Stholois present or on a pipe if
3161e60b1a3Sjmc.Pf |\ \& Ar cmd
3176ab05f83Stholois present), separated by the current output field separator,
3186ab05f83Stholoand terminated by the output record separator.
31980343d32Saaron.Ar file
3206ab05f83Stholoand
32180343d32Saaron.Ar cmd
3226ab05f83Stholomay be literal names or parenthesized expressions;
3236ab05f83Stholoidentical string values in different statements denote
3246ab05f83Stholothe same open file.
3256ab05f83StholoThe
32680343d32Saaron.Ic printf
327c062391aSmillertstatement formats its expression list according to the
328c062391aSmillert.Ar format
3296ab05f83Stholo(see
330b26504ffSjmc.Xr printf 1 ) .
331e624cbe1Sjmc.Pp
332e624cbe1SjmcPatterns are arbitrary Boolean combinations
333e624cbe1Sjmc(with
334e624cbe1Sjmc.Ic "\&! || &&" )
335e624cbe1Sjmcof regular expressions and
336e624cbe1Sjmcrelational expressions.
3370271f2dcSjmc.Nm
3380271f2dcSjmcsupports extended regular expressions
3390271f2dcSjmc.Pq EREs .
3400271f2dcSjmcSee
3410271f2dcSjmc.Xr re_format 7
3420271f2dcSjmcfor more information on regular expressions.
343e624cbe1SjmcIsolated regular expressions
344e624cbe1Sjmcin a pattern apply to the entire line.
345e624cbe1SjmcRegular expressions may also occur in
346e624cbe1Sjmcrelational expressions, using the operators
347e624cbe1Sjmc.Ic ~
348e624cbe1Sjmcand
349e624cbe1Sjmc.Ic !~ .
350b60214d1Sschwarze.Pf / Ar re Ns /
351e624cbe1Sjmcis a constant regular expression;
352e624cbe1Sjmcany string (constant or variable) may be used
35314c49119Sjmcas a regular expression,
35414c49119Sjmcexcept in the position of an isolated regular expression in a pattern.
355e624cbe1Sjmc.Pp
356e624cbe1SjmcA pattern may consist of two patterns separated by a comma;
357e624cbe1Sjmcin this case, the action is performed for all lines
358e624cbe1Sjmcfrom an occurrence of the first pattern
359e624cbe1Sjmcthrough an occurrence of the second.
360e624cbe1Sjmc.Pp
361e624cbe1SjmcA relational expression is one of the following:
362489d5c95Sjmc.Pp
363489d5c95Sjmc.Bl -tag -width Ds -offset indent -compact
364489d5c95Sjmc.It Ar expression matchop regular-expression
365489d5c95Sjmc.It Ar expression relop expression
366489d5c95Sjmc.It Ar expression Ic in Ar array-name
367489d5c95Sjmc.It Xo Ic \&( Ns
368e624cbe1Sjmc.Ar expr , expr , \&... Ns Ic \&) in
369489d5c95Sjmc.Ar array-name
370e624cbe1Sjmc.Xc
371489d5c95Sjmc.El
372e624cbe1Sjmc.Pp
373e624cbe1Sjmcwhere a
374e624cbe1Sjmc.Ar relop
375e624cbe1Sjmcis any of the six relational operators in C, and a
376e624cbe1Sjmc.Ar matchop
377e624cbe1Sjmcis either
378e624cbe1Sjmc.Ic ~
379e624cbe1Sjmc(matches)
380e624cbe1Sjmcor
381e624cbe1Sjmc.Ic !~
382e624cbe1Sjmc(does not match).
383e624cbe1SjmcA conditional is an arithmetic expression,
384e624cbe1Sjmca relational expression,
385e624cbe1Sjmcor a Boolean combination
386e624cbe1Sjmcof these.
387e624cbe1Sjmc.Pp
3883f582d5fSderaadtThe special pattern
389e624cbe1Sjmc.Ic BEGIN
3903f582d5fSderaadtmay be used to capture control before the first input line is read.
3913f582d5fSderaadtThe special pattern
392e624cbe1Sjmc.Ic END
3933f582d5fSderaadtmay be used to capture control after processing is finished.
394e624cbe1Sjmc.Ic BEGIN
395e624cbe1Sjmcand
396e624cbe1Sjmc.Ic END
397e624cbe1Sjmcdo not combine with other patterns.
398c062391aSmillertThey may appear multiple times in a program and execute
399c062391aSmillertin the order they are read by
400c062391aSmillert.Nm .
401e624cbe1Sjmc.Pp
402e624cbe1SjmcVariable names with special meanings:
403e624cbe1Sjmc.Pp
404e624cbe1Sjmc.Bl -tag -width "FILENAME " -compact
405e624cbe1Sjmc.It Va ARGC
406e624cbe1SjmcArgument count, assignable.
407e624cbe1Sjmc.It Va ARGV
408e624cbe1SjmcArgument array, assignable;
409e624cbe1Sjmcnon-null members are taken as filenames.
410e624cbe1Sjmc.It Va CONVFMT
411e624cbe1SjmcConversion format when converting numbers
412e624cbe1Sjmc(default
413e624cbe1Sjmc.Qq Li %.6g ) .
414e624cbe1Sjmc.It Va ENVIRON
415e624cbe1SjmcArray of environment variables; subscripts are names.
416e624cbe1Sjmc.It Va FILENAME
417e624cbe1SjmcThe name of the current input file.
418e624cbe1Sjmc.It Va FNR
419e624cbe1SjmcOrdinal number of the current record in the current file.
420e624cbe1Sjmc.It Va FS
42142fb2d3dSmillertRegular expression used to separate fields (default whitespace);
42242fb2d3dSmillertalso settable by option
423c613704cSjmc.Fl F Ar fs .
424e624cbe1Sjmc.It Va NF
425e624cbe1SjmcNumber of fields in the current record.
426e624cbe1Sjmc.Va $NF
427e624cbe1Sjmccan be used to obtain the value of the last field in the current record.
428e624cbe1Sjmc.It Va NR
429e624cbe1SjmcOrdinal number of the current record.
430e624cbe1Sjmc.It Va OFMT
431e624cbe1SjmcOutput format for numbers (default
432e624cbe1Sjmc.Qq Li %.6g ) .
433e624cbe1Sjmc.It Va OFS
434e624cbe1SjmcOutput field separator (default blank).
435e624cbe1Sjmc.It Va ORS
436e624cbe1SjmcOutput record separator (default newline).
437e624cbe1Sjmc.It Va RLENGTH
438e624cbe1SjmcThe length of the string matched by the
439e624cbe1Sjmc.Fn match
440e624cbe1Sjmcfunction.
441e624cbe1Sjmc.It Va RS
442e624cbe1SjmcInput record separator (default newline).
443ec104564SmillertIf empty, blank lines separate records.
444ec104564SmillertIf more than one character long,
445ec104564Smillert.Va RS
446ec104564Smillertis treated as a regular expression, and records are
447ec104564Smillertseparated by text matching the expression.
448e624cbe1Sjmc.It Va RSTART
449e624cbe1SjmcThe starting position of the string matched by the
450e624cbe1Sjmc.Fn match
451e624cbe1Sjmcfunction.
452e624cbe1Sjmc.It Va SUBSEP
453e624cbe1SjmcSeparates multiple subscripts (default 034).
454e624cbe1Sjmc.El
4551e60b1a3Sjmc.Sh FUNCTIONS
4561e60b1a3SjmcThe awk language has a variety of built-in functions:
457a8b74d42Sjmcarithmetic, string, input/output, general, and bit-operation.
458a8b74d42Sjmc.Pp
459a8b74d42SjmcFunctions may be defined (at the position of a pattern-action statement)
460a8b74d42Sjmcthusly:
461a8b74d42Sjmc.Pp
462a8b74d42Sjmc.Dl function foo(a, b, c) { ...; return x }
463a8b74d42Sjmc.Pp
464a8b74d42SjmcParameters are passed by value if scalar, and by reference if array name;
465a8b74d42Sjmcfunctions may be called recursively.
466a8b74d42SjmcParameters are local to the function; all other variables are global.
467a8b74d42SjmcThus local variables may be created by providing excess parameters in
468a8b74d42Sjmcthe function definition.
4691e60b1a3Sjmc.Ss Arithmetic Functions
4701e60b1a3Sjmc.Bl -tag -width "atan2(y, x)"
4711e60b1a3Sjmc.It Fn atan2 y x
4721e60b1a3SjmcReturn the arctangent of
4731e60b1a3Sjmc.Fa y Ns / Ns Fa x
4741e60b1a3Sjmcin radians.
4751e60b1a3Sjmc.It Fn cos x
4761e60b1a3SjmcReturn the cosine of
4771e60b1a3Sjmc.Fa x ,
4781e60b1a3Sjmcwhere
4791e60b1a3Sjmc.Fa x
4801e60b1a3Sjmcis in radians.
4811e60b1a3Sjmc.It Fn exp x
4821e60b1a3SjmcReturn the exponential of
4831e60b1a3Sjmc.Fa x .
4841e60b1a3Sjmc.It Fn int x
4851e60b1a3SjmcReturn
4861e60b1a3Sjmc.Fa x
4871e60b1a3Sjmctruncated to an integer value.
4881e60b1a3Sjmc.It Fn log x
4891e60b1a3SjmcReturn the natural logarithm of
4901e60b1a3Sjmc.Fa x .
49180343d32Saaron.It Fn rand
4921e60b1a3SjmcReturn a random number,
4931e60b1a3Sjmc.Fa n ,
4941e60b1a3Sjmcsuch that
4951e60b1a3Sjmc.Sm off
4961e60b1a3Sjmc.Pf 0 \*(Le Fa n No \*(Lt 1 .
4971e60b1a3Sjmc.Sm on
49822f61fd1StimRandom numbers are non-deterministic unless a seed is explicitly set with
49922f61fd1Stim.Fn srand .
5001e60b1a3Sjmc.It Fn sin x
5011e60b1a3SjmcReturn the sine of
5021e60b1a3Sjmc.Fa x ,
5031e60b1a3Sjmcwhere
5041e60b1a3Sjmc.Fa x
5051e60b1a3Sjmcis in radians.
5061e60b1a3Sjmc.It Fn sqrt x
5071e60b1a3SjmcReturn the square root of
5081e60b1a3Sjmc.Fa x .
5091e60b1a3Sjmc.It Fn srand expr
510daef5724SjmcSets seed for
51180343d32Saaron.Fn rand
5121e60b1a3Sjmcto
5131e60b1a3Sjmc.Fa expr
5146ab05f83Stholoand returns the previous seed.
5151e60b1a3SjmcIf
5161e60b1a3Sjmc.Fa expr
51722f61fd1Stimis omitted,
51822f61fd1Stim.Fn rand
51922f61fd1Stimwill return non-deterministic random numbers.
5201e60b1a3Sjmc.El
5211e60b1a3Sjmc.Ss String Functions
5221e60b1a3Sjmc.Bl -tag -width "split(s, a, fs)"
523b79e3a79Smillert.It Fn gensub r s h [t]
524b79e3a79SmillertSearch the target string
525b79e3a79Smillert.Ar t
526b79e3a79Smillertfor matches of the regular expression
527b79e3a79Smillert.Ar r .
528b79e3a79SmillertIf
529b79e3a79Smillert.Ar h
530b79e3a79Smillertis a string beginning with
531b79e3a79Smillert.Ic g
532b79e3a79Smillertor
533b79e3a79Smillert.Ic G ,
534b79e3a79Smillertthen replace all matches of
535b79e3a79Smillert.Ar r
536b79e3a79Smillertwith
537b79e3a79Smillert.Ar s .
538b79e3a79SmillertOtherwise,
539b79e3a79Smillert.Ar h
540b79e3a79Smillertis a number indicating which match of
541b79e3a79Smillert.Ar r
542b79e3a79Smillertto replace.
543b79e3a79SmillertIf no
544b79e3a79Smillert.Ar t
545b79e3a79Smillertis supplied,
546b79e3a79Smillert.Va $0
547b79e3a79Smillertis used instead.
548b79e3a79Smillert.\"Within the replacement text
549b79e3a79Smillert.\".Ar s ,
550b79e3a79Smillert.\"the sequence
551b79e3a79Smillert.\".Ar \en ,
552b79e3a79Smillert.\"where
553b79e3a79Smillert.\".Ar n
554b79e3a79Smillert.\"is a digit from 1 to 9, may be used to indicate just the text that
555b79e3a79Smillert.\"matched the
556b79e3a79Smillert.\".Ar n Ap th
557b79e3a79Smillert.\"parenthesized subexpression.
558b79e3a79Smillert.\"The sequence
559b79e3a79Smillert.\".Ic \e0
560b79e3a79Smillert.\"represents the entire text, as does the character
561b79e3a79Smillert.\".Ic & .
562b79e3a79SmillertUnlike
563b79e3a79Smillert.Fn sub
564b79e3a79Smillertand
565b79e3a79Smillert.Fn gsub ,
566b79e3a79Smillertthe modified string is returned as the result of the function,
567b79e3a79Smillertand the original target is
568b79e3a79Smillert.Em not
569b79e3a79Smillertchanged.
570b79e3a79SmillertNote that
571b79e3a79Smillert.Ar \en
572b79e3a79Smillertsequences within the replacement string
573b79e3a79Smillert.Ar s ,
574b79e3a79Smillertas supported by GNU
575b79e3a79Smillert.Nm ,
576b79e3a79Smillertare
577b79e3a79Smillert.Em not
578b79e3a79Smillertsupported at this time.
5791e60b1a3Sjmc.It Fn gsub r t s
5801e60b1a3SjmcThe same as
5811e60b1a3Sjmc.Fn sub
5821e60b1a3Sjmcexcept that all occurrences of the regular expression are replaced.
5831e60b1a3Sjmc.Fn gsub
5841e60b1a3Sjmcreturns the number of replacements.
58580343d32Saaron.It Fn index s t
586daef5724SjmcThe position in
58780343d32Saaron.Fa s
5886ab05f83Stholowhere the string
58980343d32Saaron.Fa t
5906ab05f83Stholooccurs, or 0 if it does not.
5911e60b1a3Sjmc.It Fn length s
5921e60b1a3SjmcThe length of
5931e60b1a3Sjmc.Fa s
5941e60b1a3Sjmctaken as a string,
595c062391aSmillertnumber of elements in an array for an array argument,
596c062391aSmillertor length of
5971e60b1a3Sjmc.Va $0
5981e60b1a3Sjmcif no argument is given.
59980343d32Saaron.It Fn match s r
600daef5724SjmcThe position in
60180343d32Saaron.Fa s
6026ab05f83Stholowhere the regular expression
60380343d32Saaron.Fa r
6046ab05f83Stholooccurs, or 0 if it does not.
6051e60b1a3SjmcThe variable
60680343d32Saaron.Va RSTART
6071e60b1a3Sjmcis set to the starting position of the matched string
6081e60b1a3Sjmc.Pq which is the same as the returned value
6091e60b1a3Sjmcor zero if no match is found.
6101e60b1a3SjmcThe variable
61180343d32Saaron.Va RLENGTH
6121e60b1a3Sjmcis set to the length of the matched string,
6131e60b1a3Sjmcor \-1 if no match is found.
61480343d32Saaron.It Fn split s a fs
615daef5724SjmcSplits the string
61680343d32Saaron.Fa s
6176ab05f83Stholointo array elements
61880343d32Saaron.Va a[1] , a[2] , ... , a[n]
6196ab05f83Stholoand returns
62080343d32Saaron.Va n .
6216ab05f83StholoThe separation is done with the regular expression
62280343d32Saaron.Ar fs
6236ab05f83Stholoor with the field separator
62480343d32Saaron.Va FS
6256ab05f83Stholoif
62680343d32Saaron.Ar fs
6276ab05f83Stholois not given.
6286ab05f83StholoAn empty string as field separator splits the string
6296ab05f83Stholointo one array element per character.
6301e60b1a3Sjmc.It Fn sprintf fmt expr ...
6311e60b1a3SjmcThe string resulting from formatting
6321e60b1a3Sjmc.Fa expr , ...
6331e60b1a3Sjmcaccording to the
634b26504ffSjmc.Xr printf 1
6351e60b1a3Sjmcformat
6361e60b1a3Sjmc.Fa fmt .
63780343d32Saaron.It Fn sub r t s
638daef5724SjmcSubstitutes
63980343d32Saaron.Fa t
6406ab05f83Stholofor the first occurrence of the regular expression
64180343d32Saaron.Fa r
6426ab05f83Stholoin the string
64380343d32Saaron.Fa s .
6446ab05f83StholoIf
64580343d32Saaron.Fa s
6466ab05f83Stholois not given,
64780343d32Saaron.Va $0
6486ab05f83Stholois used.
6491e60b1a3SjmcAn ampersand
6501e60b1a3Sjmc.Pq Sq &
6511e60b1a3Sjmcin
6521e60b1a3Sjmc.Fa t
6531e60b1a3Sjmcis replaced in string
6541e60b1a3Sjmc.Fa s
6551e60b1a3Sjmcwith regular expression
6561e60b1a3Sjmc.Fa r .
6571e60b1a3SjmcA literal ampersand can be specified by preceding it with two backslashes
6581e60b1a3Sjmc.Pq Sq \e\e .
6591e60b1a3SjmcA literal backslash can be specified by preceding it with another backslash
6601e60b1a3Sjmc.Pq Sq \e\e .
66180343d32Saaron.Fn sub
6621e60b1a3Sjmcreturns the number of replacements.
6631e60b1a3Sjmc.It Fn substr s m n
6641e60b1a3SjmcReturn at most the
6651e60b1a3Sjmc.Fa n Ns -character
6661e60b1a3Sjmcsubstring of
6671e60b1a3Sjmc.Fa s
6681e60b1a3Sjmcthat begins at position
6691e60b1a3Sjmc.Fa m
6701e60b1a3Sjmccounted from 1.
6711e60b1a3SjmcIf
6721e60b1a3Sjmc.Fa n
6731e60b1a3Sjmcis omitted, or if
6741e60b1a3Sjmc.Fa n
6751e60b1a3Sjmcspecifies more characters than are left in the string,
6761e60b1a3Sjmcthe length of the substring is limited by the length of
6771e60b1a3Sjmc.Fa s .
67880343d32Saaron.It Fn tolower str
679daef5724SjmcReturns a copy of
68080343d32Saaron.Fa str
6816ab05f83Stholowith all upper-case characters translated to their
6826ab05f83Stholocorresponding lower-case equivalents.
68380343d32Saaron.It Fn toupper str
684daef5724SjmcReturns a copy of
68580343d32Saaron.Fa str
6866ab05f83Stholowith all lower-case characters translated to their
6876ab05f83Stholocorresponding upper-case equivalents.
68880343d32Saaron.El
689b79e3a79Smillert.Ss Time Functions
690b79e3a79SmillertThis version of
691b79e3a79Smillert.Nm
692b79e3a79Smillertprovides the following functions for obtaining and formatting time
693b79e3a79Smillertstamps.
694b79e3a79Smillert.Bl -tag -width indent
6952ed04c87Smillert.It Fn mktime datespec
6962ed04c87SmillertConverts
6972ed04c87Smillert.Fa datespec
6982ed04c87Smillertinto a timestamp in the same form as a value returned by
6992ed04c87Smillert.Fn systime .
7002ed04c87SmillertThe
7012ed04c87Smillert.Fa datespec
7022ed04c87Smillertis a string composed of six or seven numbers separated by whitespace:
7032ed04c87Smillert.Bd -literal -offset indent
7042ed04c87SmillertYYYY MM DD HH MM SS [DST]
7052ed04c87Smillert.Ed
7062ed04c87Smillert.Pp
7072ed04c87SmillertThe fields in
7082ed04c87Smillert.Fa datespec
7092ed04c87Smillertare as follows:
7102ed04c87Smillert.Bl -tag -width "YYYY"
71145ea7078Smillert.It YYYY
7122ed04c87SmillertYear: a four-digit year, including the century.
7132ed04c87Smillert.It MM
7142ed04c87SmillertMonth: a number from 1 to 12.
7152ed04c87Smillert.It DD
7162ed04c87SmillertDay: a number from 1 to 31.
7172ed04c87Smillert.It HH
7182ed04c87SmillertHour: a number from 0 to 23.
7192ed04c87Smillert.It MM
7202ed04c87SmillertMinute: a number from 0 to 59.
7212ed04c87Smillert.It SS
7222ed04c87SmillertSecond: a number from 0 to 60 (permitting a leap second).
7232ed04c87Smillert.It DST
7242ed04c87SmillertDaylight Saving Time: a positive or zero value indicates that
7252ed04c87SmillertDST is or is not in effect.
7262ed04c87SmillertIf DST is not specified, or is negative,
7272ed04c87Smillert.Fn mktime
7282ed04c87Smillertwill attempt to determine the correct value.
7292ed04c87Smillert.El
730b79e3a79Smillert.It Fn strftime "[format [, timestamp]]"
731b79e3a79SmillertFormats
732b79e3a79Smillert.Ar timestamp
733b79e3a79Smillertaccording to the string
734b79e3a79Smillert.Ar format .
735b79e3a79SmillertThe format string may contain any of the conversion specifications described
736b79e3a79Smillertin the
737b79e3a79Smillert.Xr strftime 3
738b79e3a79Smillertmanual page, as well as any arbitrary text.
739b79e3a79SmillertThe
740b79e3a79Smillert.Ar timestamp
741b79e3a79Smillertmust be in the same form as a value returned by
7422ed04c87Smillert.Fn mktime
7432ed04c87Smillertand
744b79e3a79Smillert.Fn systime .
745b79e3a79SmillertIf
746b79e3a79Smillert.Ar timestamp
747b79e3a79Smillertis not specified, the current time is used.
748b79e3a79SmillertIf
749b79e3a79Smillert.Ar format
750b79e3a79Smillertis not specified, a default format equivalent to the output of
751b79e3a79Smillert.Xr date 1
752b79e3a79Smillertis used.
753b79e3a79Smillert.It Fn systime
754b79e3a79SmillertReturns the value of time in seconds since 0 hours, 0 minutes,
755b79e3a79Smillert0 seconds, January 1, 1970, Coordinated Universal Time (UTC).
756b79e3a79Smillert.El
7571e60b1a3Sjmc.Ss Input/Output and General Functions
7581e60b1a3Sjmc.Bl -tag -width "getline [var] < file"
7591e60b1a3Sjmc.It Fn close expr
7601e60b1a3SjmcCloses the file or pipe
7611e60b1a3Sjmc.Fa expr .
7621e60b1a3Sjmc.Fa expr
7631e60b1a3Sjmcshould match the string that was used to open the file or pipe.
7641e60b1a3Sjmc.It Ar cmd | Ic getline Op Va var
7651e60b1a3SjmcRead a record of input from a stream piped from the output of
7661e60b1a3Sjmc.Ar cmd .
7671e60b1a3SjmcIf
7681e60b1a3Sjmc.Va var
7691e60b1a3Sjmcis omitted, the variables
77080343d32Saaron.Va $0
7711e60b1a3Sjmcand
7721e60b1a3Sjmc.Va NF
7731e60b1a3Sjmcare set.
7741e60b1a3SjmcOtherwise
7751e60b1a3Sjmc.Va var
7761e60b1a3Sjmcis set.
7771e60b1a3SjmcIf the stream is not open, it is opened.
7781e60b1a3SjmcAs long as the stream remains open, subsequent calls
7791e60b1a3Sjmcwill read subsequent records from the stream.
7801e60b1a3SjmcThe stream remains open until explicitly closed with a call to
7811e60b1a3Sjmc.Fn close .
78264ac1292Sjmc.Ic getline
78364ac1292Sjmcreturns 1 for a successful input, 0 for end of file, and \-1 for an error.
78464ac1292Sjmc.It Fn fflush [expr]
78513ce2bc5SjmcFlushes any buffered output for the file or pipe
78664ac1292Sjmc.Fa expr ,
78764ac1292Sjmcor all open files or pipes if
78864ac1292Sjmc.Fa expr
78964ac1292Sjmcis omitted.
7901e60b1a3Sjmc.Fa expr
7911e60b1a3Sjmcshould match the string that was used to open the file or pipe.
7921e60b1a3Sjmc.It Ic getline
793*52752bf4SnaddyReads the next record from the current input file.
7941e60b1a3SjmcThis form of
7951e60b1a3Sjmc.Ic getline
7961e60b1a3Sjmcsets the variables
797*52752bf4Snaddy.Va $0 ,
7981e60b1a3Sjmc.Va NF ,
7991e60b1a3Sjmc.Va NR ,
8001e60b1a3Sjmcand
8011e60b1a3Sjmc.Va FNR .
8021e60b1a3Sjmc.Ic getline
8031e60b1a3Sjmcreturns 1 for a successful input, 0 for end of file, and \-1 for an error.
8041e60b1a3Sjmc.It Ic getline Va var
805*52752bf4SnaddyReads the next record from the current input file.
8061e60b1a3SjmcThis form of
8071e60b1a3Sjmc.Ic getline
8081e60b1a3Sjmcsets the variables
809*52752bf4Snaddy.Va var ,
8101e60b1a3Sjmc.Va NR
8111e60b1a3Sjmcand
8121e60b1a3Sjmc.Va FNR .
8131e60b1a3Sjmc.Ic getline
8141e60b1a3Sjmcreturns 1 for a successful input, 0 for end of file, and \-1 for an error.
8151e60b1a3Sjmc.It Xo
8161e60b1a3Sjmc.Ic getline Op Va var
817c062391aSmillert.Pf <\ \& Ar file
8181e60b1a3Sjmc.Xc
819*52752bf4SnaddyReads the next record from
82080343d32Saaron.Ar file .
8211e60b1a3SjmcIf
8221e60b1a3Sjmc.Va var
8231e60b1a3Sjmcis omitted, the variables
8241e60b1a3Sjmc.Va $0
8251e60b1a3Sjmcand
8261e60b1a3Sjmc.Va NF
8271e60b1a3Sjmcare set.
8281e60b1a3SjmcOtherwise
8291e60b1a3Sjmc.Va var
8301e60b1a3Sjmcis set.
8311e60b1a3SjmcIf
8321e60b1a3Sjmc.Ar file
8331e60b1a3Sjmcis not open, it is opened.
8341e60b1a3SjmcAs long as the stream remains open, subsequent calls will read subsequent
8351e60b1a3Sjmcrecords from
8361e60b1a3Sjmc.Ar file .
8371e60b1a3Sjmc.Ar file
8381e60b1a3Sjmcremains open until explicitly closed with a call to
8391e60b1a3Sjmc.Fn close .
8401e60b1a3Sjmc.It Fn system cmd
8411e60b1a3SjmcExecutes
8421e60b1a3Sjmc.Fa cmd
8431e60b1a3Sjmcand returns its exit status.
844c062391aSmillertThis will be \-1 upon error,
845c062391aSmillert.Ar cmd Ns 's
846c062391aSmillertexit status upon a normal exit,
847c062391aSmillert256 +
848c062391aSmillert.Em sig
849c062391aSmillertif
850c062391aSmillert.Fa cmd
851c062391aSmillertwas terminated by a signal, where
852c062391aSmillert.Em sig
853c062391aSmillertis the number of the signal,
854c062391aSmillertor 512 +
855c062391aSmillert.Em sig
856c062391aSmillertif there was a core dump.
8571e60b1a3Sjmc.El
858a8b74d42Sjmc.Ss Bit-Operation Functions
85977d6dbf8Spyr.Bl -tag -width "lshift(a, b)"
86077d6dbf8Spyr.It Fn compl x
86177d6dbf8SpyrReturns the bitwise complement of integer argument x.
86277d6dbf8Spyr.It Fn and x y
863a8b74d42SjmcPerforms a bitwise AND on integer arguments x and y.
86477d6dbf8Spyr.It Fn or x y
865a8b74d42SjmcPerforms a bitwise OR on integer arguments x and y.
86677d6dbf8Spyr.It Fn xor x y
867a8b74d42SjmcPerforms a bitwise Exclusive-OR on integer arguments x and y.
86877d6dbf8Spyr.It Fn lshift x n
86913ce2bc5SjmcReturns integer argument x shifted by n bits to the left.
87077d6dbf8Spyr.It Fn rshift x n
87113ce2bc5SjmcReturns integer argument x shifted by n bits to the right.
87277d6dbf8Spyr.El
873fabd211eSmillert.Sh ENVIRONMENT
874fabd211eSmillertThe following environment variables affect the execution of
875fabd211eSmillert.Nm :
876fabd211eSmillert.Bl -tag -width POSIXLY_CORRECT
87760756c6aSschwarze.It Ev LC_CTYPE
87860756c6aSschwarzeThe character encoding
87960756c6aSschwarze.Xr locale 1 .
88060756c6aSschwarzeIt decides which byte sequences form characters, which characters are
88160756c6aSschwarzeletters, and how letters are mapped from lower to upper case and vice versa.
88260756c6aSschwarzeIf unset or set to
88360756c6aSschwarze.Qq C ,
88460756c6aSschwarze.Qq POSIX ,
88560756c6aSschwarzeor an unsupported value, each byte is treated as a character,
88660756c6aSschwarzeand non-ASCII bytes are not regarded as letters.
887fabd211eSmillert.It Ev POSIXLY_CORRECT
888fabd211eSmillertWhen set, behave in accordance with the standard, even when it conflicts
889fabd211eSmillertwith historical behavior.
890fabd211eSmillert.El
8917d1ae8aeSjmc.Sh EXIT STATUS
8927d1ae8aeSjmc.Ex -std awk
8937d1ae8aeSjmc.Pp
8947d1ae8aeSjmcBut note that the
8957d1ae8aeSjmc.Ic exit
8967d1ae8aeSjmcexpression can modify the exit status.
89780343d32Saaron.Sh EXAMPLES
898daef5724SjmcPrint lines longer than 72 characters:
899daef5724Sjmc.Pp
90080343d32Saaron.Dl length($0) > 72
901daef5724Sjmc.Pp
902daef5724SjmcPrint first two fields in opposite order:
90380343d32Saaron.Pp
90480343d32Saaron.Dl { print $2, $1 }
905daef5724Sjmc.Pp
906c062391aSmillertSame, with input fields separated by comma and/or spaces and tabs:
90780343d32Saaron.Bd -literal -offset indent
9086ab05f83StholoBEGIN { FS = ",[ \et]*|[ \et]+" }
9096ab05f83Stholo      { print $2, $1 }
91080343d32Saaron.Ed
911daef5724Sjmc.Pp
912daef5724SjmcAdd up first column, print sum and average:
91380343d32Saaron.Bd -literal -offset indent
9146ab05f83Stholo{ s += $1 }
9156ab05f83StholoEND { print "sum is", s, " average is", s/NR }
91680343d32Saaron.Ed
917daef5724Sjmc.Pp
918daef5724SjmcPrint all lines between start/stop pairs:
91980343d32Saaron.Pp
92080343d32Saaron.Dl /start/, /stop/
921daef5724Sjmc.Pp
922ed9166ddSnaddySimulate
923ed9166ddSnaddy.Xr echo 1 :
92480343d32Saaron.Bd -literal -offset indent
9256ab05f83StholoBEGIN { # Simulate echo(1)
9266ab05f83Stholo        for (i = 1; i < ARGC; i++) printf "%s ", ARGV[i]
9276ab05f83Stholo        printf "\en"
9286ab05f83Stholo        exit }
92980343d32Saaron.Ed
930b38c71d1Sjmc.Pp
931b38c71d1SjmcPrint an error message to standard error:
932b38c71d1Sjmc.Bd -literal -offset indent
933b38c71d1Sjmc{ print "error!" > "/dev/stderr" }
934b38c71d1Sjmc.Ed
935483fa115Smillert.Sh UNUSUAL FLOATING-POINT VALUES
936483fa115Smillert.Nm
937483fa115Smillertwas designed before IEEE 754 arithmetic defined Not-A-Number (NaN)
938483fa115Smillertand Infinity values, which are supported by all modern floating-point
939483fa115Smillerthardware.
940483fa115Smillert.Pp
941483fa115SmillertBecause
942483fa115Smillert.Nm
943483fa115Smillertuses
944483fa115Smillert.Xr strtod 3
945483fa115Smillertand
946483fa115Smillert.Xr atof 3
947483fa115Smillertto convert string values to double-precision floating-point values,
948483fa115Smillertmodern C libraries also convert strings starting with
949483fa115Smillert.Dv inf
950483fa115Smillertand
951483fa115Smillert.Dv nan
952483fa115Smillertinto infinity and NaN values respectively.
953483fa115SmillertThis led to strange results,
954483fa115Smillertwith something like this:
955483fa115Smillert.Pp
956483fa115Smillert.Li echo nancy | awk '{ print $1 + 0 }'
957483fa115Smillert.Pp
958483fa115Smillertprinting
959483fa115Smillert.Dv nan
960483fa115Smillertinstead of zero.
961483fa115Smillert.Pp
962483fa115Smillert.Nm
963483fa115Smillertnow follows GNU
964483fa115Smillert.Nm ,
965483fa115Smillertand prefilters string values before attempting
966483fa115Smillertto convert them to numbers, as follows:
967483fa115Smillert.Bl -tag -width Ds
968483fa115Smillert.It Hexadecimal values
969483fa115SmillertHexadecimal values (allowed since C99) convert to zero, as they did
970483fa115Smillertprior to C99.
971483fa115Smillert.It NaN values
972483fa115SmillertThe two strings
973483fa115Smillert.Dq +NAN
974483fa115Smillertand
975483fa115Smillert.Dq -NAN
976483fa115Smillert(case independent) convert to NaN.
977483fa115SmillertNo others do.
978483fa115Smillert(NaNs can have signs.)
979483fa115Smillert.It Infinity values
980483fa115SmillertThe two strings
981483fa115Smillert.Dq +INF
982483fa115Smillertand
983483fa115Smillert.Dq -INF
984483fa115Smillert(case independent) convert to positive and negative infinity, respectively.
985483fa115SmillertNo others do.
986483fa115Smillert.El
98780343d32Saaron.Sh SEE ALSO
9880893c481Stedu.Xr cut 1 ,
989b79e3a79Smillert.Xr date 1 ,
990c062391aSmillert.Xr grep 1 ,
99180343d32Saaron.Xr lex 1 ,
99244123e9cSjmc.Xr printf 1 ,
993daef5724Sjmc.Xr sed 1 ,
994b79e3a79Smillert.Xr strftime 3 ,
9956d2e264bSjmc.Xr re_format 7 ,
9966d2e264bSjmc.Xr script 7
99780343d32Saaron.Rs
998093fc5b9Sjsg.\" 4.4BSD USD:16
9994f4ed0d0Sjsg.\".%R Computing Science Technical Report
10004f4ed0d0Sjsg.\".%N 68
10014f4ed0d0Sjsg.\".%D July 1978
1002093fc5b9Sjsg.%A A. V. Aho
1003093fc5b9Sjsg.%A P. J. Weinberger
1004093fc5b9Sjsg.%A B. W. Kernighan
1005093fc5b9Sjsg.%T AWK \(em A Pattern Scanning and Processing Language
10064f4ed0d0Sjsg.%J Software \(em Practice and Experience
10074f4ed0d0Sjsg.%V 9:4
10084f4ed0d0Sjsg.%P pp. 267-279
10094f4ed0d0Sjsg.%D April 1979
1010093fc5b9Sjsg.Re
1011093fc5b9Sjsg.Rs
101280343d32Saaron.%A A. V. Aho
101380343d32Saaron.%A B. W. Kernighan
101480343d32Saaron.%A P. J. Weinberger
101580343d32Saaron.%T The AWK Programming Language
101680343d32Saaron.%I Addison-Wesley
10179c4ac39bSjsg.%D 2024
10189c4ac39bSjsg.%O ISBN 0-13-826972-6
101980343d32Saaron.Re
10207c5a075bSjmc.Sh STANDARDS
10217c5a075bSjmcThe
10227c5a075bSjmc.Nm
10237c5a075bSjmcutility is compliant with the
10247f786bddSjmc.St -p1003.1-2024
1025fabd211eSmillertspecification except that consecutive backslashes in the replacement
1026fabd211eSmillertstring argument for
1027fabd211eSmillert.Fn sub
1028fabd211eSmillertand
1029fabd211eSmillert.Fn gsub
1030ef789615Smillertare not collapsed and a slash
1031ef789615Smillert.Pq Ql /
1032ef789615Smillertdoes not need to be escaped in a bracket expression.
103322f61fd1StimAlso, the behaviour of
103422f61fd1Stim.Fn rand
103522f61fd1Stimand
103622f61fd1Stim.Fn srand
103722f61fd1Stimhas been changed to support non-deterministic random numbers.
10387c5a075bSjmc.Pp
10397c5a075bSjmcThe flags
10407a6df6a7Sjmc.Op Fl \&dV ,
10417a6df6a7Sjmc.Op Fl -csv ,
10427c5a075bSjmcand
10437c5a075bSjmc.Op Fl safe ,
1044ef301d81Smillertsupport for regular expressions in
1045ef301d81Smillert.Va RS ,
1046b79e3a79Smillertas well as the functions
1047b79e3a79Smillert.Fn fflush ,
1048b79e3a79Smillert.Fn gensub ,
1049b79e3a79Smillert.Fn compl ,
1050b79e3a79Smillert.Fn and ,
1051b79e3a79Smillert.Fn or ,
1052b79e3a79Smillert.Fn xor ,
1053b79e3a79Smillert.Fn lshift ,
1054b79e3a79Smillert.Fn rshift ,
10552ed04c87Smillert.Fn mktime ,
1056b79e3a79Smillert.Fn strftime
1057b79e3a79Smillertand
1058b79e3a79Smillert.Fn systime
10597c5a075bSjmcare extensions to that specification.
10603746a816Saaron.Sh HISTORY
106157149b5eSmillertAn
10623746a816Saaron.Nm
106357149b5eSmillertutility appeared in
106457149b5eSmillert.At v7 .
106580343d32Saaron.Sh BUGS
10666ab05f83StholoThere are no explicit conversions between numbers and strings.
10676ab05f83StholoTo force an expression to be treated as a number add 0 to it;
10686ab05f83Stholoto force it to be treated as a string concatenate
106980343d32Saaron.Li \&""
107080343d32Saaronto it.
107180343d32Saaron.Pp
10726ab05f83StholoThe scope rules for variables in functions are a botch;
10736ab05f83Stholothe syntax is worse.
1074