Sun Mar 15 16:21:46 2009 UTC ()
Fix and improve mark up.


(joerg)
diff -r1.18 -r1.19 src/usr.bin/awk/awk.1

cvs diff -r1.18 -r1.19 src/usr.bin/awk/Attic/awk.1 (expand / switch to unified diff)

--- src/usr.bin/awk/Attic/awk.1 2009/03/09 14:10:12 1.18
+++ src/usr.bin/awk/Attic/awk.1 2009/03/15 16:21:46 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: awk.1,v 1.18 2009/03/09 14:10:12 joerg Exp $ 1.\" $NetBSD: awk.1,v 1.19 2009/03/15 16:21:46 joerg Exp $
2.\" 2.\"
3.\" Copyright (C) Lucent Technologies 1997 3.\" Copyright (C) Lucent Technologies 1997
4.\" All Rights Reserved 4.\" All Rights Reserved
5.\" 5.\"
6.\" Permission to use, copy, modify, and distribute this software and 6.\" Permission to use, copy, modify, and distribute this software and
7.\" its documentation for any purpose and without fee is hereby 7.\" its documentation for any purpose and without fee is hereby
8.\" granted, provided that the above copyright notice appear in all 8.\" granted, provided that the above copyright notice appear in all
9.\" copies and that both that the copyright notice and this 9.\" copies and that both that the copyright notice and this
10.\" permission notice and warranty disclaimer appear in supporting 10.\" permission notice and warranty disclaimer appear in supporting
11.\" documentation, and that the name Lucent Technologies or any of 11.\" documentation, and that the name Lucent Technologies or any of
12.\" its entities not be used in advertising or publicity pertaining 12.\" its entities not be used in advertising or publicity pertaining
13.\" to distribution of the software without specific, written prior 13.\" to distribution of the software without specific, written prior
14.\" permission. 14.\" permission.
@@ -119,42 +119,43 @@ An input line is normally made up of fie @@ -119,42 +119,43 @@ An input line is normally made up of fie
119or by regular expression 119or by regular expression
120.Va FS . 120.Va FS .
121The fields are denoted 121The fields are denoted
122.Va $1 , 122.Va $1 ,
123.Va $2 , 123.Va $2 ,
124\&..., while 124\&..., while
125.Va $0 125.Va $0
126refers to the entire line. 126refers to the entire line.
127If 127If
128.Va FS 128.Va FS
129is null, the input line is split into one field per character. 129is null, the input line is split into one field per character.
130.Pp 130.Pp
131A pattern-action statement has the form 131A pattern-action statement has the form
132.sp 132.Lp
133.Dl pattern \&{ action \&} 133.Dl pattern \&{ action \&}
134.sp 134.Lp
135A missing \&{ action \&} 135A missing \&{ action \&}
136means print the line; 136means print the line;
137a missing pattern always matches. 137a missing pattern always matches.
138Pattern-action statements are separated by newlines or semicolons. 138Pattern-action statements are separated by newlines or semicolons.
139.Pp 139.Pp
140An action is a sequence of statements. 140An action is a sequence of statements.
141Statements are terminated by 141Statements are terminated by
142semicolons, newlines or right braces. 142semicolons, newlines or right braces.
143An empty 143An empty
144.Ar expression-list 144.Ar expression-list
145stands for 145stands for
146.Va $0 . 146.Va $0 .
147String constants are quoted \&\f(CW"\ "\fR, 147String constants are quoted
 148.Em \&"\ \&" ,
148with the usual C escapes recognized within. 149with the usual C escapes recognized within.
149Expressions take on string or numeric values as appropriate, 150Expressions take on string or numeric values as appropriate,
150and are built using the 151and are built using the
151.Sx Operators 152.Sx Operators
152(see next subsection). 153(see next subsection).
153Variables may be scalars, array elements 154Variables may be scalars, array elements
154(denoted 155(denoted
155.Va x[i] ) 156.Va x[i] )
156or fields. 157or fields.
157Variables are initialized to the null string. 158Variables are initialized to the null string.
158Array subscripts may be any string, 159Array subscripts may be any string,
159not necessarily numeric; 160not necessarily numeric;
160this allows for a form of associative memory. 161this allows for a form of associative memory.
@@ -193,154 +194,127 @@ String concatenation. @@ -193,154 +194,127 @@ String concatenation.
193.It Ic != == 194.It Ic != ==
194Regular relational operators 195Regular relational operators
195.It Ic ~ !~ 196.It Ic ~ !~
196Regular expression match and not match 197Regular expression match and not match
197.It Ic in 198.It Ic in
198Array membership 199Array membership
199.It Ic "\*[Am]\*[Am]" 200.It Ic "\*[Am]\*[Am]"
200Logical AND 201Logical AND
201.It Ic "||" 202.It Ic "||"
202Logical OR 203Logical OR
203.It Ic ?: 204.It Ic ?:
204C conditional expression. 205C conditional expression.
205This is used as 206This is used as
206.Ar expr1 Ic ? Ar expr2 Ic : Ar expr3 No . 207.Ar expr1 Ic \&? Ar expr2 Ic \&: Ar expr3 No .
207If 208If
208.Ar expr1 209.Ar expr1
209is true, the result value is 210is true, the result value is
210.Ar expr2 , 211.Ar expr2 ,
211otherwise it is 212otherwise it is
212.Ar expr3 . 213.Ar expr3 .
213Only one of 214Only one of
214.Ar expr2 215.Ar expr2
215and 216and
216.Ar expr3 217.Ar expr3
217is evaluated. 218is evaluated.
218.It Ic = += -= 219.It Ic = += -=
219.It Ic *= /= %= ^= 220.It Ic *= /= %= ^=
220Assignment and Operator-Assignment 221Assignment and Operator-Assignment
221.El 222.El
222.Ss Control Statements 223.Ss Control Statements
223The control statements are as follows: 224The control statements are as follows:
224.Pp 225.Pp
225.Bl -hang -offset indent -width indent -compact 226.Bl -hang -offset indent -width indent -compact
226.It Xo 227.It Ic if \&( Ar expression Ic \&) Ar statement Bq Ic else Ar statement
227.Ic if \&( Ar expression Ic \&) Ar statement 228.It Ic while \&( Ar expression Ic \&) Ar statement
228.Bq Ic else Ar statement 229.It Ic for \&( Ar expression Ic \&; Ar expression Ic \&; \
229.Xc 230Ar expression Ic \&) Ar statement
230.It Ic while( Ar expression Ic \&) Ar statement 231.It Ic for \&( Va var Ic in Ar array Ic \&) Ar statement
231.It Xo 232.It Ic do Ar statement Ic while \&( Ar expression Ic \&)
232.Ic for( Ar expression Ic \&; Ar expression Ic \&; 
233.Ar expression Ic \&) 
234.Ar statement 
235.Xc 
236.It Xo 
237.Ic for( Va var Ic in Ar array 
238.Ic \&) 
239.Ar statement 
240.Xc 
241.It Xo 
242.Ic do Ar statement 
243.Ic while( Ar expression Ic \&) 
244.Xc 
245.It Ic break 233.It Ic break
246.It Ic continue 234.It Ic continue
247.It Ic delete Va array Bq Ar expression 235.It Ic delete Va array Bq Ar expression
248.It Ic delete Va array 236.It Ic delete Va array
249.It Ic exit Bq Ar expression 237.It Ic exit Bq Ar expression
250.Ar expression 238.Ar expression
251.It Ic return Bq Ar expression 239.It Ic return Bq Ar expression
252.It Ic { Ar [ statement ... ] Ic } 240.It Ic \&{ Ar [ statement ... ] Ic \&}
253.El 241.El
254.Ss I/O Statements 242.Ss I/O Statements
255The input/output statements are as follows: 243The input/output statements are as follows:
256.Pp 244.Pp
257.Bl -tag -width indent 245.Bl -tag -width indent
258.It Fn close expr 246.It Fn close expr
259Closes the file or pipe 247Closes the file or pipe
260.Ar expr . 248.Ar expr .
261Returns zero on success; otherwise nonzero. 249Returns zero on success; otherwise nonzero.
262.It Fn fflush expr 250.It Fn fflush expr
263Flushes any buffered output for the file or pipe 251Flushes any buffered output for the file or pipe
264.Ar expr . 252.Ar expr .
265Returns zero on success; otherwise nonzero. 253Returns zero on success; otherwise nonzero.
266.It Ic getline Bq Va var 254.It Ic getline Bq Va var
267Set 255Set
268.Va var 256.Va var
269(or 257(or
270.Va $0 if 258.Va $0 if
271.Va var 259.Va var
272is not specified) 260is not specified)
273to the next input record from the current input file. 261to the next input record from the current input file.
274.Ic getline 262.Ic getline
275returns 1 for a successful input, 263returns 1 for a successful input,
2760 for end of file, and \-1 for an error. 2640 for end of file, and \-1 for an error.
277.It Xo 265.It Ic getline Bo Va var Bc Ic \*[Lt] Ar file
278.Ic getline 
279.Bq Va var 
280.Ic \*[Lt] 
281.Ar file 
282.Xc 
283Set 266Set
284.Va var 267.Va var
285(or 268(or
286.Va $0 if 269.Va $0 if
287.Va var 270.Va var
288is not specified) 271is not specified)
289to the next input record from the specified file 272to the next input record from the specified file
290.Ar file . 273.Ar file .
291.It Ar expr Ic \&| getline 274.It Ar expr Ic \&| getline
292Pipes the output of 275Pipes the output of
293.Ar expr 276.Ar expr
294into 277into
295.Ic getline ; 278.Ic getline ;
296each call of 279each call of
297.Ic getline 280.Ic getline
298returns the next line of output from 281returns the next line of output from
299.Ar expr . 282.Ar expr .
300.It Ic next 283.It Ic next
301Skip remaining patterns on this input line. 284Skip remaining patterns on this input line.
302.It Ic nextfile 285.It Ic nextfile
303Skip rest of this file, open next, start at top. 286Skip rest of this file, open next, start at top.
304.It Xo 287.It Ic print Bo Ar expr-list Bc Bq Ic \*[Gt] Ar file
305.Ic print 
306.Bq Ar expr-list 
307.Bq Ic \*[Gt] Ar file 
308.Xc 
309The 288The
310.Ic print 289.Ic print
311statement prints its arguments on the standard output (or to a file 290statement prints its arguments on the standard output (or to a file
312if 291if
313.Ic \*[Gt] file 292.Ic \*[Gt] file
314or to a pipe if 293or to a pipe if
315.Ic | Ar expr 294.Ic | Ar expr
316is present), 295is present),
317separated by the current output field separator 296separated by the current output field separator
318.Va OFS , 297.Va OFS ,
319and terminated by the 298and terminated by the
320output record separator 299output record separator
321.Va ORS . 300.Va ORS .
322Both 301Both
323.Ar file 302.Ar file
324and 303and
325.Ar expr 304.Ar expr
326may be literal names or parenthesized expressions; identical string values in 305may be literal names or parenthesized expressions; identical string values in
327different statements denote the same open file. 306different statements denote the same open file.
328.It Xo 307.It Ic printf Ar format Bo Ic \&, Ar expr-list Bc Bq Ic \*[Gt] Ar file
329.Ic printf 
330.Ar format 
331.Bq Ic , Ar expr-list 
332.Bq Ic \*[Gt] Ar file 
333.Xc 
334Format and print its expression list according to 308Format and print its expression list according to
335.Ar format . 309.Ar format .
336See 310See
337.Xr printf 3 311.Xr printf 3
338for list of supported formats and their meaning. 312for list of supported formats and their meaning.
339.El 313.El
340.Ss Mathematical and Numeric Functions 314.Ss Mathematical and Numeric Functions
341AWK has the following mathematical and numerical functions built-in: 315AWK has the following mathematical and numerical functions built-in:
342.Pp 316.Pp
343.Bl -tag -width indent 317.Bl -tag -width indent
344.It Fn atan2 x y 318.It Fn atan2 x y
345Returns the arctangent of 319Returns the arctangent of
346.Ar x Ic / Ar y 320.Ar x Ic / Ar y
@@ -691,37 +665,35 @@ Functions may be defined (at the positio @@ -691,37 +665,35 @@ Functions may be defined (at the positio
691.Ic function foo(a, b, c) { ...; return x } 665.Ic function foo(a, b, c) { ...; return x }
692.Ed 666.Ed
693.Pp 667.Pp
694Parameters are passed by value if scalar and by reference if array name; 668Parameters are passed by value if scalar and by reference if array name;
695functions may be called recursively. 669functions may be called recursively.
696Parameters are local to the function; all other variables are global. 670Parameters are local to the function; all other variables are global.
697Thus local variables may be created by providing excess parameters in 671Thus local variables may be created by providing excess parameters in
698the function definition. 672the function definition.
699.Sh EXAMPLES 673.Sh EXAMPLES
700.Bl -tag -width indent -compact 674.Bl -tag -width indent -compact
701.It Ic length($0) \*[Gt] 72 675.It Ic length($0) \*[Gt] 72
702Print lines longer than 72 characters. 676Print lines longer than 72 characters.
703.Pp 677.Pp
704.It Ic { print $2, $1 } 678.It Ic \&{ print $2, $1 \&}
705Print first two fields in opposite order. 679Print first two fields in opposite order.
706.Pp 680.Pp
707.It Ic BEGIN { FS = \&",[ \et]*|[ \et]+\&" } 681.It Ic BEGIN { FS = \&",[ \et]*|[ \et]+\&" }
708.It Ic "\ \ \ \ \ \ {" print \&$2, \&$1 } 682.It Ic "\ \ \ \ \ \ {" print \&$2, \&$1 }
709Same, with input fields separated by comma and/or blanks and tabs. 683Same, with input fields separated by comma and/or blanks and tabs.
710.Pp 684.Pp
711.It Ic "\ \ \ \ {" s += $1 } 685.It Ic "\ \ \ \ {" s += $1 }
712.It Xo 686.It Ic END { print \&"sum is\&", s, \&" average is\ \&",\ s/NR\ }
713.Ic END { print \&"sum is\&", s, \&" average is\ \&",\ s/NR\ } 
714.Xc 
715Add up first column, print sum and average. 687Add up first column, print sum and average.
716.Pp 688.Pp
717.It Ic /start/, /stop/ 689.It Ic /start/, /stop/
718Print all lines between start/stop pairs. 690Print all lines between start/stop pairs.
719.Pp 691.Pp
720.It Ic BEGIN { # Simulate echo(1) 692.It Ic BEGIN { # Simulate echo(1)
721.It Ic "\ \ \ \ " for (i = 1; i \*[Lt] ARGC;\ i++)\ printf\ \&"%s\ \&",\ ARGV[i] 693.It Ic "\ \ \ \ " for (i = 1; i \*[Lt] ARGC;\ i++)\ printf\ \&"%s\ \&",\ ARGV[i]
722.It Ic "\ \ \ \ " printf \&"\en\&" 694.It Ic "\ \ \ \ " printf \&"\en\&"
723.It Ic "\ \ \ \ " exit } 695.It Ic "\ \ \ \ " exit }
724.El 696.El
725.Sh SEE ALSO 697.Sh SEE ALSO
726.Xr egrep 1 , 698.Xr egrep 1 ,
727.Xr lex 1 , 699.Xr lex 1 ,
@@ -745,16 +717,16 @@ Edition 1.0, published by the Free Softw @@ -745,16 +717,16 @@ Edition 1.0, published by the Free Softw
745.Sh HISTORY 717.Sh HISTORY
746.Nm nawk 718.Nm nawk
747has been the default system 719has been the default system
748.Nm 720.Nm
749since 721since
750.Nx 2.0 , 722.Nx 2.0 ,
751replacing the previously used GNU 723replacing the previously used GNU
752.Nm . 724.Nm .
753.Sh BUGS 725.Sh BUGS
754There are no explicit conversions between numbers and strings. 726There are no explicit conversions between numbers and strings.
755To force an expression to be treated as a number add 0 to it; 727To force an expression to be treated as a number add 0 to it;
756to force it to be treated as a string concatenate 728to force it to be treated as a string concatenate
757\&"\&" to it. 729\&"\&" to it.
758.br 730.Pp
759The scope rules for variables in functions are a botch; 731The scope rules for variables in functions are a botch;
760the syntax is worse. 732the syntax is worse.