home *** CD-ROM | disk | FTP | other *** search
-
-
-
- aaaawwwwkkkk((((1111)))) aaaawwwwkkkk((((1111))))
-
-
-
- NNNNAAAAMMMMEEEE
- aaaawwwwkkkk, nnnnaaaawwwwkkkk, ppppaaaawwwwkkkk - pattern scanning and processing language
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- aaaawwwwkkkk [----FFFF _r_e] [----vvvv _v_a_r=_v_a_l_u_e] [''''_p_r_o_g''''] [_f_i_l_e. . .]
- aaaawwwwkkkk [----FFFF _r_e] [----vvvv _v_a_r=_v_a_l_u_e] [----ffff _p_r_o_g_f_i_l_e] [_f_i_l_e. . .]
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- NNNNOOOOTTTTEEEE:::: This version of awk has some incompatibilities with previous
- versions. See the COMPATIBILITY ISSUES section below for more detail.
-
- aaaawwwwkkkk and nnnnaaaawwwwkkkk use the old rrrreeeeggggeeeexxxxpppp(((()))) and ccccoooommmmppppiiiilllleeee(((()))) regular expression
- routines. When the environment variable ____XXXXPPPPGGGG is equal to 1111 (one), ppppaaaawwwwkkkk
- is exec'ed which uses the newer rrrreeeeggggccccoooommmmpppp(((()))) and rrrreeeeggggeeeexxxxeeeecccc(((()))) routines which
- implement the Extended Regular Expression package.
-
- aaaawwwwkkkk scans each input _f_i_l_e for lines that match any of a set of patterns
- specified in _p_r_o_g. The _p_r_o_g string must be enclosed in single quotes ('''')
- to protect it from the shell. Patterns are arbitrary Boolean
- combinations of regular expressions and relational expressions. For each
- pattern in _p_r_o_g there may be an associated action performed when a line
- of a _f_i_l_e matches the pattern. The set of pattern-action statements may
- appear literally as _p_r_o_g or in a file specified with the ----ffff _p_r_o_g_f_i_l_e
- option. Input files are read in order; if there are no files, the
- standard input is read. The file name ---- means the standard input.
-
- aaaawwwwkkkk processes supplementary code set characters in pattern-action
- statements and comments, and recognizes supplementary code set characters
- as field separators (see below) according to the locale specified in the
- LLLLCCCC____CCCCTTTTYYYYPPPPEEEE environment variable [see LLLLAAAANNNNGGGG on eeeennnnvvvviiiirrrroooonnnn(5)]. In regular
- expressions, pattern searches are performed on characters, not bytes, as
- described on eeeedddd(1).
-
- Each input line is matched against the pattern portion of every pattern-
- action statement; the associated action is performed for each matched
- pattern. Any _f_i_l_e of the form vvvvaaaarrrr=_v_a_l_u_e 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 ----vvvv followed by vvvvaaaarrrr=_v_a_l_u_e is an assignment to
- be done before _p_r_o_g is executed; any number of ----vvvv options may be present.
-
- An input line is normally made up of fields separated by white space.
- (This default can be changed by using the FFFFSSSS built-in variable or the ----FFFF
- _r_e option.) The fields are denoted $$$$1111, $$$$2222, ...; $$$$0000 refers to the entire
- line.
-
- A pattern-action statement has the form:
-
- _p_a_t_t_e_r_n {{{{ _a_c_t_i_o_n }}}}
-
- Either pattern or action may be omitted. If there is no action with a
- pattern, the matching line is printed. If there is no pattern with an
- action, the action is performed on every input line. Pattern-action
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- aaaawwwwkkkk((((1111)))) aaaawwwwkkkk((((1111))))
-
-
-
- statements are separated by newlines or semicolons.
-
- As noted, patterns are arbitrary Boolean combinations ( !!!!, ||, &&&&&&&&, and
- parentheses) of relational expressions and regular expressions. A
- relational expression is one of the following:
-
- _e_x_p_r_e_s_s_i_o_n _r_e_l_o_p _e_x_p_r_e_s_s_i_o_n
- _e_x_p_r_e_s_s_i_o_n _m_a_t_c_h_o_p _r_e_g_u_l_a_r__e_x_p_r_e_s_s_i_o_n
- _e_x_p_r_e_s_s_i_o_n iiiinnnn _a_r_r_a_y-_n_a_m_e
- ((((_e_x_p_r_e_s_s_i_o_n,,,,_e_x_p_r_e_s_s_i_o_n,,,, ... )))) iiiinnnn _a_r_r_a_y-_n_a_m_e
-
- where a _r_e_l_o_p is any of the six relational operators in C, and a _m_a_t_c_h_o_p
- is either ~~~~ (contains) or !!!!~~~~ (does not contain). An _e_x_p_r_e_s_s_i_o_n is an
- arithmetic expression, a relational expression, the special expression
-
- _v_a_r iiiinnnn _a_r_r_a_y
-
- or a Boolean combination of these.
-
- Regular expressions are as in eeeeggggrrrreeeepppp(1). In patterns they must be
- surrounded by slashes. Isolated regular expressions in a pattern apply
- to the entire line. Regular expressions may also occur in relational
- expressions. A pattern may consist of two patterns separated by a comma;
- in this case, the action is performed for all lines between an occurrence
- of the first pattern and the next occurrence of the second pattern.
-
- The special patterns BBBBEEEEGGGGIIIINNNN and EEEENNNNDDDD may be used to capture control before
- the first input line has been read and after the last input line has been
- read respectively. These keywords do not combine with any other
- patterns.
-
- A regular expression may be used to separate fields by using the ----FFFF _r_e
- option or by assigning the expression to the built-in variable FS. The
- default is to ignore leading blanks and to separate fields by blanks
- and/or tab characters. However, if FS is assigned a value, leading
- blanks are no longer ignored.
-
- Other built-in variables include:
-
- AAAARRRRGGGGCCCC command line argument count
-
- AAAARRRRGGGGVVVV command line argument array
-
- EEEENNNNVVVVIIIIRRRROOOONNNN array of environment variables; subscripts are names
-
- FFFFIIIILLLLEEEENNNNAAAAMMMMEEEE name of the current input file
-
- FFFFNNNNRRRR ordinal number of the current record in the current
- file
-
-
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-
-
-
- aaaawwwwkkkk((((1111)))) aaaawwwwkkkk((((1111))))
-
-
-
- FFFFSSSS input field separator regular expression (default
- blank and tab)
-
- NNNNFFFF number of fields in the current record
-
- NNNNRRRR ordinal number of the current record
-
- OOOOFFFFMMMMTTTT output format for numbers (default %%%%....6666gggg)
-
- OOOOFFFFSSSS output field separator (default blank)
-
- OOOORRRRSSSS output record separator (default new-line)
-
- RRRRSSSS input record separator (default new-line)
-
- SSSSUUUUBBBBSSSSEEEEPPPP separates multiple subscripts (default is 034)
-
- The field separators specified with the ----FFFF option or with the variables
- OOOOFFFFSSSS, OOOORRRRSSSS, and FFFFSSSS may be supplementary code set characters.
-
- An action is a sequence of statements. A statement may be one of the
- following:
-
- iiiiffff ( _e_x_p_r_e_s_s_i_o_n ) _s_t_a_t_e_m_e_n_t [ eeeellllsssseeee _s_t_a_t_e_m_e_n_t ]
- wwwwhhhhiiiilllleeee ( _e_x_p_r_e_s_s_i_o_n ) _s_t_a_t_e_m_e_n_t
- ddddoooo _s_t_a_t_e_m_e_n_t wwwwhhhhiiiilllleeee ( _e_x_p_r_e_s_s_i_o_n )
- ffffoooorrrr ( _e_x_p_r_e_s_s_i_o_n ; _e_x_p_r_e_s_s_i_o_n ; _e_x_p_r_e_s_s_i_o_n ) _s_t_a_t_e_m_e_n_t
- ffffoooorrrr ( _v_a_r iiiinnnn _a_r_r_a_y ) _s_t_a_t_e_m_e_n_t
- ddddeeeelllleeeetttteeee _a_r_r_a_y[_s_u_b_s_c_r_i_p_t] #delete an array element
- bbbbrrrreeeeaaaakkkk
- ccccoooonnnnttttiiiinnnnuuuueeee
- { [ _s_t_a_t_e_m_e_n_t ] ... }
- _e_x_p_r_e_s_s_i_o_n # commonly variable = expression
- pppprrrriiiinnnntttt [ _e_x_p_r_e_s_s_i_o_n-_l_i_s_t ] [ >_e_x_p_r_e_s_s_i_o_n ]
- pppprrrriiiinnnnttttffff _f_o_r_m_a_t [ , _e_x_p_r_e_s_s_i_o_n-_l_i_s_t ] [ >_e_x_p_r_e_s_s_i_o_n ]
- nnnneeeexxxxtttt # skip remaining patterns on this input line
- eeeexxxxiiiitttt [eeeexxxxpppprrrr] # skip the rest of the input; exit status is expr
- rrrreeeettttuuuurrrrnnnn [eeeexxxxpppprrrr]
-
- Statements are terminated by semicolons, new-lines, or right braces. An
- empty expression-list stands for the whole input line. Expressions take
- on string or numeric values as appropriate, and are built using the
- operators ++++, ----, ****, ////, %%%%, ^^^^ and concatenation (indicated by a blank). The
- operators ++++++++ -------- ++++==== ----==== ****==== ////==== %%%%==== ^^^^==== >>>> >>>>==== <<<< <<<<==== ======== !!!!==== ????:::: are also available
- in expressions. Variables may be scalars, array elements (denoted x[i]),
- or fields. Variables are initialized to the null string or zero. Array
- subscripts may be any string, not necessarily numeric; this allows for a
- form of associative memory. Multiple subscripts such as [[[[iiii,,,,jjjj,,,,kkkk]]]] are
- permitted; the constituents are concatenated, separated by the value of
- SSSSUUUUBBBBSSSSEEEEPPPP. String constants are quoted (""""""""), with the usual C escapes
- recognized within.
-
-
-
-
- PPPPaaaaggggeeee 3333
-
-
-
-
-
-
- aaaawwwwkkkk((((1111)))) aaaawwwwkkkk((((1111))))
-
-
-
- A comment consists of any characters beginning with the number sign
- character and terminated by, but excluding the next occurrence of, a
- newline character. Comments will have no effect, except to delimit
- statements.
-
- The pppprrrriiiinnnntttt statement prints its arguments on the standard output, or on a
- file if >>>>_e_x_p_r_e_s_s_i_o_n is present, or on a pipe if | _c_m_d is present. The
- arguments are separated by the current output field separator and
- terminated by the output record separator. The pppprrrriiiinnnnttttffff statement formats
- its expression list according to the format (see pppprrrriiiinnnnttttffff(3S)). The
- built-in function cccclllloooosssseeee(_e_x_p_r) closes the file or pipe _e_x_p_r.
-
- The mathematical functions: aaaattttaaaannnn2222, ccccoooossss, eeeexxxxpppp, lllloooogggg, ssssiiiinnnn, ssssqqqqrrrrtttt, are built-
- in.
-
- Other built-in functions include:
-
- ggggssssuuuubbbb(_f_o_r, _r_e_p_l, _i_n)
- behaves like ssssuuuubbbb (see below), except that it replaces
- successive occurrences of the regular expression (like the eeeedddd
- global substitute command).
-
- iiiinnnnddddeeeexxxx((((_s,,,, _t))))
- returns the position in string _s where string _t first occurs,
- or 0 if it does not occur at all.
-
- iiiinnnntttt truncates to an integer value.
-
- lllleeeennnnggggtttthhhh((((_s)))) returns the length in bytes of its argument taken as a string,
- or of the whole line if there is no argument.
-
- mmmmaaaattttcccchhhh((((_s,,,, _r_e))))
- returns the position in string _s where the regular expression
- _r_e occurs, or 0 if it does not occur at all. RRRRSSSSTTTTAAAARRRRTTTT is set to
- the starting position (which is the same as the returned
- value), and RRRRLLLLEEEENNNNGGGGTTTTHHHH is set to the length of the matched string.
-
- rrrraaaannnndddd random number on (0, 1).
-
- sssspppplllliiiitttt((((_s,,,, _a,,,, _f_s))))
- splits the string _s into array elements _a[_1], _a[_2], _a[_n], and
- returns _n. The separation is done with the regular expression
- _f_s or with the field separator FFFFSSSS if _f_s is not given.
-
- ssssrrrraaaannnndddd sets the seed for rrrraaaannnndddd
-
- sssspppprrrriiiinnnnttttffff((((_f_m_t,,,, _e_x_p_r,,,, _e_x_p_r,,,,...))))
- formats the expressions according to the pppprrrriiiinnnnttttffff(3S) format
- given by _f_m_t and returns the resulting string.
-
-
-
-
-
-
- PPPPaaaaggggeeee 4444
-
-
-
-
-
-
- aaaawwwwkkkk((((1111)))) aaaawwwwkkkk((((1111))))
-
-
-
- ssssuuuubbbb(_f_o_r, _r_e_p_l, _i_n)
- substitutes the string _r_e_p_l in place of the first instance of
- the regular expression _f_o_r in string _i_n and returns the number
- of substitutions. If _i_n is omitted, aaaawwwwkkkk substitutes in the
- current record ($$$$0000).
-
- ssssuuuubbbbssssttttrrrr(_s, _m, _n)
- returns the _n-byte substring of _s that begins at position _m.
-
- ttttoooolllloooowwwweeeerrrr(_s)
- converts all upper-case alphabetic characters in string _s to
- lower-case. Numbers and other characters are not affected.
-
- ttttoooouuuuppppppppeeeerrrr(_s)
- converts all lower-case alphabetic characters in string _s to
- upper-case. Numbers and other characters are not affected.
-
-
- The input/output built-in functions are:
-
- cccclllloooosssseeee((((_f_i_l_e_n_a_m_e))))
- closes the file or pipe named _f_i_l_e_n_a_m_e.
-
- _c_m_d |||| ggggeeeettttlllliiiinnnneeee
- pipes the output of _c_m_d into ggggeeeettttlllliiiinnnneeee; each successive call to
- _g_e_t_l_i_n_e returns the next line of output from _c_m_d.
-
- ggggeeeettttlllliiiinnnneeee sets $$$$0000 to the next input record from the current input file.
-
- ggggeeeettttlllliiiinnnneeee <<<<_f_i_l_e
- sets $$$$0000 to the next record from _f_i_l_e.
-
- ggggeeeettttlllliiiinnnneeee _x sets variable _x instead.
-
- ggggeeeettttlllliiiinnnneeee _x <<<<_f_i_l_e
- sets _x from the next record of _f_i_l_e.
-
- ssssyyyysssstttteeeemmmm((((_c_m_d))))
- executes _c_m_d and returns its exit status.
-
- All forms of ggggeeeettttlllliiiinnnneeee return 1 for successful input, 0 for end of file,
- and -1 for an error.
-
- aaaawwwwkkkk also provides user-defined functions. Such functions may be defined
- (in the pattern position of a pattern-action statement) as
-
- _ffff_uuuu_nnnn_cccc_tttt_iiii_oooo_nnnn _n_a_m_e_((((_a_r_g_s_,,,,..._)))) _{{{{ _s_t_m_t_s _}}}}
-
- Function arguments are passed by value if scalar and by reference if
- array name. Argument names are local to the function; all other variable
- names are global. Function calls may be nested and functions may be
- recursive. The rrrreeeettttuuuurrrrnnnn statement may be used to return a value.
-
-
-
- PPPPaaaaggggeeee 5555
-
-
-
-
-
-
- aaaawwwwkkkk((((1111)))) aaaawwwwkkkk((((1111))))
-
-
-
- EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
- Print lines longer than 72 characters:
-
- length > 72
-
- Print first two fields in opposite order:
-
- { print $2, $1 }
-
- Same, with input fields separated by comma and/or blanks and tabs:
- BEGIN { FS = ",[ \t]*|[ \t]+" }
- { print $2, $1 }
-
-
- Add up first column, print sum and average:
-
- { s += $1 }
- END { print "sum is", s, " average is", s/NR }
-
- Print fields in reverse order:
-
- { for (i = NF; i > 0; --i) print $i }
-
- Print all lines between start/stop pairs:
-
- /start/, /stop/
-
- Print all lines whose first field is different from previous one:
-
- $1 != prev { print; prev = $1 }
-
- Simulate eeeecccchhhhoooo(1):
-
- BEGIN {
- for (i = 1; i < ARGC; i++)
- printf "%s", ARGV[i]
- printf "\n"
- exit
- }
-
- Print a file, filling in page numbers starting at 5:
-
- /Page/ { $2 = n++; }
- { print }
-
- Assuming this program is in a file named pppprrrroooogggg, the following command line
- prints the file iiiinnnnppppuuuutttt numbering its pages starting at 5: awk -f prog n=5
- input.
-
-
-
-
-
- PPPPaaaaggggeeee 6666
-
-
-
-
-
-
- aaaawwwwkkkk((((1111)))) aaaawwwwkkkk((((1111))))
-
-
-
- FFFFIIIILLLLEEEESSSS
- /usr/lib/locale/locale/LC_MESSAGES/uxawk
- language-specific message file (see LLLLAAAANNNNGGGG on eeeennnnvvvviiiirrrroooonnnn(5))
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- ooooaaaawwwwkkkk(1), eeeeggggrrrreeeepppp(1), ggggrrrreeeepppp(1), lllleeeexxxx(1), ppppeeeerrrrllll(1), sssseeeedddd(1), pppprrrriiiinnnnttttffff(3S)
- A. V. Aho, B. W. Kernighan, P. J. Weinberger, _T_h_e _a_w_k _P_r_o_g_r_a_m_m_i_n_g
- _L_a_n_g_u_a_g_e Addison-Wesley, 1988
-
- NNNNOOOOTTTTEEEESSSS aaaannnndddd CCCCOOOOMMMMPPPPAAAATTTTIIIIBBBBIIIILLLLIIIITTTTYYYY IIIISSSSSSSSUUUUEEEESSSS
- aaaawwwwkkkk is a newer version that provides capabilities unavailable in previous
- versions. See ooooaaaawwwwkkkk(1) for the older version.
-
- Input white space is not preserved on output if fields are involved.
-
- 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 the null string ("""""""") to it.
-
- The following regular expressions are no longer accepted:
-
- ////[[[[]]]]//// ////[[[[^^^^]]]]//// ////[[[[\\\\]]]]]]]]////
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 7777
-
-
-
-