⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 awk.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<td align=left>n/a<tr valign=top><td align=left>+ <i>expr</i><td align=left>Unary plus<td align=left>numeric<td align=left>n/a<tr valign=top><td align=left>- <i>expr</i><td align=left>Unary minus<td align=left>numeric<td align=left>n/a<tr valign=top><td align=left><i>expr</i> * <i>expr</i><td align=left>Multiplication<td align=left>numeric<td align=left>left<tr valign=top><td align=left><i>expr</i> / <i>expr</i><td align=left>Division<td align=left>numeric<td align=left>left<tr valign=top><td align=left><i>expr</i> % <i>expr</i><td align=left>Modulus<td align=left>numeric<td align=left>left<tr valign=top><td align=left><i>expr</i> + <i>expr</i><td align=left>Addition<td align=left>numeric<td align=left>left<tr valign=top><td align=left><i>expr</i> - <i>expr</i><td align=left>Subtraction<td align=left>numeric<td align=left>left<tr valign=top><td align=left><i>expr</i> <i>expr</i><td align=left>String concatenation<td align=left>string<td align=left>left<tr valign=top><td align=left><i>expr</i> &lt; <i>expr</i><td align=left>Less than<td align=left>numeric<td align=left>none<tr valign=top><td align=left><i>expr</i> &lt;= <i>expr</i><td align=left>Less than or equal to<td align=left>numeric<td align=left>none<tr valign=top><td align=left><i>expr</i> != <i>expr</i><td align=left>Not equal to<td align=left>numeric<td align=left>none<tr valign=top><td align=left><i>expr</i> == <i>expr</i><td align=left>Equal to<td align=left>numeric<td align=left>none<tr valign=top><td align=left><i>expr</i> &gt; <i>expr</i><td align=left>Greater than<td align=left>numeric<td align=left>none<tr valign=top><td align=left><i>expr</i> &gt;= <i>expr</i><td align=left>Greater than or equal to<td align=left>numeric<td align=left>none<tr valign=top><td align=left><i>expr</i> ~ <i>expr</i><td align=left>ERE match<td align=left>numeric<td align=left>none<tr valign=top><td align=left><i>expr</i> !~ <i>expr</i><td align=left>ERE non-match<td align=left>numeric<td align=left>none<tr valign=top><td align=left><i>expr</i> in array<td align=left>Array membership<td align=left>numeric<td align=left>left<tr valign=top><td align=left>( <i>index</i> ) in <i>array</i><td align=left>Multi-dimension array membership<td align=left>numeric<td align=left>left<tr valign=top><td align=left><i>expr</i> &amp;&amp; <i>expr</i><td align=left>Logical AND<td align=left>numeric<td align=left>left<tr valign=top><td align=left><i>expr</i> || <i>expr</i><td align=left>Logical OR<td align=left>numeric<td align=left>left<tr valign=top><td align=left><i>expr1</i> ? <i>expr2</i> : <i>expr3</i><td align=left>Conditional expression<td align=left>type of selected <i>expr2</i> or <i>expr3</i><td align=left>right<tr valign=top><td align=left><i>lvalue</i> ^= <i>expr</i><td align=left>Exponentiation assignment<td align=left>numeric<td align=left>right<tr valign=top><td align=left><i>lvalue</i> %= <i>expr</i><td align=left>Modulus assignment<td align=left>numeric<td align=left>right<tr valign=top><td align=left><i>lvalue</i> *= <i>expr</i><td align=left>Multiplication assignment<td align=left>numeric<td align=left>right<tr valign=top><td align=left><i>lvalue</i> /= <i>expr</i><td align=left>Division assignment<td align=left>numeric<td align=left>right<tr valign=top><td align=left><i>lvalue</i> += <i>expr</i><td align=left>Addition assignment<td align=left>numeric<td align=left>right<tr valign=top><td align=left><i>lvalue</i> -= <i>expr</i><td align=left>Subtraction assignment<td align=left>numeric<td align=left>right<tr valign=top><td align=left><i>lvalue</i> = <i>expr</i><td align=left>Assignment<td align=left>type of <i>expr</i><td align=left>right</table></pre><h6 align=center><xref table="Expressions in Decreasing Precedence in <I>awk</i>"></xref>Table: Expressions in Decreasing Precedence in <i>awk</i></h6><xref type="7" name="awkprec"></xref><hr size=2 noshade><p>Each expression has either a string value, a numeric value or both.Except as stated for specific contexts,the value of an expression will be implicitly converted to the typeneeded for the context in which it is used.A string value will be converted to a numeric value by the equivalent of thefollowing calls to functions defined by the ISO&nbsp;C standard:<pre><code>setlocale(LC_NUMERIC, "");<i>numeric_value</i> = atof(<i>string_value</i>);</code></pre>A numeric value that is exactly equal to the value of an integerwill be converted to a string by the equivalent of acall to the<b>sprintf</b>function (see<xref href=awkstr><a href="#tag_000_000_108_013">String Functions</a></xref>)with the string%das the<i>fmt</i>argument and the numeric value being converted as the first and only<i>expr</i>argument.Any other numeric value will be converted to a string by the equivalent of acall to the<b>sprintf</b>function with the value of the variable<b>CONVFMT</b>as the<i>fmt</i>argument and the numeric value being converted as the first and only<i>expr</i>argument.The result of the conversion is unspecified if the value of<b>CONVFMT</b>is not a floating-point format specification.This specification specifies no explicit conversions between numbersand strings.An application can force an expression to be treated as anumber by adding zero to it, or can force it to be treatedas a string by concatenating the null string("")to it.<p>A string value will be considered to be a<i>numeric string</i>in the following case:<ol><p><li>Any leading and trailingblank characterswill be ignored.<p><li>If the first unignored character is a"+" or "-", it will be ignored.<p><li>If the remaining unignored characters would be lexically recognised as a<b>NUMBER</b>token (as described by the lexical conventions in<xref href=awkgram><a href="#tag_000_000_108_016">Grammar</a></xref>),the string will be considered a<i>numeric string .</i><p></ol><p>If a "-" character is ignored in the above steps, the numericvalue of the<i>numeric string</i>will be the negation of the numeric value of the recognised<b>NUMBER</b>token.Otherwise the numeric value of the<i>numeric string</i>will be the numeric value of the recognised<b>NUMBER</b>token.Whether or not a string is a<i>numeric string</i>will be relevant only in contexts where that term is used in this section.<p>When an expression is used in a Boolean context,if it has a numeric value, a value of zero is treated as false andany other value is treated as true.Otherwise, a string value of the null string is treated as false andany other value is treated as true.A Boolean context is one of the following:<ul><p><li>the first subexpression of a conditional expression<p><li>an expression operated on by logical NOT, logical AND or logical OR<p><li>the second expression of a<b>for</b>statement<p><li>the expression of an<b>if</b>statement<p><li>the expression of the<b>while</b>clause in either a<b>while</b>or<b>do...while</b>statement<p><li>an expression used as a pattern (as in Overall Program Structure).<p></ul><p>All arithmetic will follow the semantics of floating-point arithmeticas specified by the ISO&nbsp;C standard.<p>The value of the expression:<pre><code><i>expr1</i> ^ <i>expr2</i></code></pre>will be equivalent to the value returned by the ISO&nbsp;C standardfunction call:<pre><code>pow(<i>expr1</i>, <i>expr2</i>)</code></pre><p>The expression:<pre><code><i>lvalue</i> ^= <i>expr</i></code></pre>will be equivalent to the ISO&nbsp;C standard expression:<pre><code><i>lvalue</i> = pow(<i>lvalue</i>, <i>expr</i>)</code></pre>except that<i>lvalue</i>will be evaluated only once.The value of the expression:<pre><code><i>expr1</i> % <i>expr2</i></code></pre>will be equivalent to the value returned by the ISO&nbsp;C standard function call:<pre><code>fmod(<i>expr1</i>, <i>expr2</i>)</code></pre>The expression:<pre><code><i>lvalue</i> %= <i>expr</i></code></pre>will be equivalent to the ISO&nbsp;C standard expression:<pre><code><i>lvalue</i> = fmod(<i>lvalue</i>, <i>expr</i>)</code></pre>except that<i>lvalue</i>will be evaluated only once.<p>Variables and fields will be set by the assignment statement:<pre><code><i>lvalue</i> = <i>expression</i></code></pre>and the type of<i>expression</i>will determine the resulting variable type.The assignment includes the arithmetic assignments(<b>+=</b>, <b>-=</b>, <b>*=</b>, <b>/=</b>, <b>%=</b>, <b>^=</b>,<b>++</b>, <b>--</b>) all ofwhich produce a numeric result.The left-hand side of an assignmentand the target of increment and decrement operators can be one ofa variable, an array with index or a field selector.<p>The<i>awk</i>language supplies arrays that are used for storing numbers or strings.Arrays need not be declared.They are initially empty,and their sizes will change dynamically.The subscripts,or element identifiers,are strings, providing a type of associative array capability.An array name followed by a subscript within square brackets canbe used as an<i>lvalue</i>and thus as an expression, as described in the grammar (see<xref href=awkgram><a href="#tag_000_000_108_016">Grammar</a></xref>).Unsubscripted array names can be used in only the following contexts:<ul><p><li>a parameter in a function definition or function call<p><li>the<b>NAME</b>token following any use of the keyword<b>in</b>as specified in the grammar (see<xref href=awkgram><a href="#tag_000_000_108_016">Grammar</a></xref>);if the name used in this context is not an array name, the behaviouris undefined.<p></ul><p>A valid array<i>index</i>consists of one or more comma-separated expressions,similar to the way in which multi-dimensional arrays are indexed insome programming languages.Because<i>awk</i>arrays are really one dimensional,such a comma-separated listwill be converted to a single stringby concatenating the string values of the separate expressions,each separated from the other by the value of the<b>SUBSEP</b>variable.Thus, the following two index operations will be equivalent:<pre><code><i>var</i><b>[</b><i>expr1</i>, <i>expr2</i>, ... <i>exprn</i><b>]</b><i>var</i><b>[</b><i>expr1</i> SUBSEP <i>expr2</i> SUBSEP ... SUBSEP <i>exprn</i><b>]</b></code></pre><p>A multi-dimensioned<i>index</i>used with the<b>in</b>operator must be parenthesised.The<b>in</b>operator,which tests for the existence of a particular array element,will not cause that element to exist.Any other reference to a non-existent array element will automaticallycreate it.<p>Comparisons (with the "&lt;", "&lt;=", "!=", "==", "&gt;" and "&gt;=" operators)will be made numerically if both operands are numeric or if oneis numeric and the other has a string value that is a numeric string.Otherwise, operands will be converted to strings as requiredand a string comparison will be madeusing the locale-specific collation sequence.The value of the comparison expression will be1if the relation is true, or0if the relation is false.<h5><a name = "tag_000_000_108_003">&nbsp;</a>Variables and Special Variables</h5>Variables can be used in an<i>awk</i>program by referencing them.With the exception of function parameters (see<xref href=awkuser><a href="#tag_000_000_108_015">User-defined Functions</a></xref>),they are not explicitly declared.Uninitialised scalar variables and array elements have botha numeric value of zero anda string value of the empty string.<p>Field variables are designated by a "$"followed by a number or numerical expression.The effect of the field number<i>expression</i>evaluating to anything other than a non-negative integeris unspecified;uninitialised variables or string values need not be converted tonumeric values in this context.New field variables can be created by assigning a value to them.References to non-existent fields (that is, fields after<b>$NF</b>),will produce the null string.However, assigning to a non-existent field(for example, $(NF +2)= 5)will increase the value of<b>NF</b>,create any intervening fields with the null string as their valuesand cause the value of$0to be recomputed, with the fields being separated by the value of<b>OFS</b>.Each field variable will have a string value when created.If the string,with any occurrence of the decimal-point character from thecurrent locale changed to aperiod character,would be considered a<i>numeric string</i>(see<xref href=awkexpr><a href="#tag_000_000_108_002">Expressions in awk</a></xref>),the field variable will also have the numeric value of the<i>numeric string .</i><p>Implementations support the following other special variablesthat are set by<i>awk</i>:<dl compact><dt><b>ARGC</b><dd>The number of elements in the<b>ARGV</b>array.<dt><b>ARGV</b><dd>An array of command line arguments, excluding options andthe <i>program</i> argument, numbered from zero toARGC-1.The arguments in<b>ARGV</b>can be modified or added to;<b>ARGC</b>can be altered.As each input file ends,<i>awk</i>will treat the next non-null element of<b>ARGV</b>,up to the current value ofARGC-1,inclusive,as the name of the next input file.Thus,setting an element of<b>ARGV</b>to null means that it will not be treated as an

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -