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

📄 ch33_11.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 4 页
字号:
CLASS="literal">close</CODE></DT><DDCLASS="listitem"><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"><CODECLASS="literal">close(</CODE><CODECLASS="replaceable"><I>filename-expr</I></CODE><CODECLASS="literal">)</CODE><CODECLASS="literal">close(</CODE><CODECLASS="replaceable"><I>command-expr</I></CODE><CODECLASS="literal">)</CODE></PRE></BLOCKQUOTE>In some implementations of <EMCLASS="emphasis">awk</EM>, you can have only ten files open<ACLASS="indexterm"NAME="AUTOID-37624"></A>simultaneously and one pipe; modern versions allow more than one pipe open.Therefore, <EMCLASS="emphasis">nawk</EM> provides a <EMCLASS="emphasis">close</EM>statement that allows you to close a file or a pipe. <EMCLASS="emphasis">close</EM> takesas an argument the same expression that opened the pipeor file. (<EMCLASS="emphasis">nawk</EM>)</P></DD><DTCLASS="term"><CODECLASS="literal">continue</CODE></DT><DDCLASS="listitem"><PCLASS="para">Begin next iteration of <EMCLASS="emphasis">while</EM>, <EMCLASS="emphasis">for</EM>, or <EMCLASS="emphasis">do</EM> loop immediately.<ACLASS="indexterm"NAME="AUTOID-37638"></A>&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">cos</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">cos(</CODE><CODECLASS="replaceable"><I>x</I></CODE><CODECLASS="literal">)</CODE>Return cosine of <CODECLASS="replaceable"><I>x</I></CODE> (in radians).<ACLASS="indexterm"NAME="AUTOID-37649"></A>(<EMCLASS="emphasis">nawk</EM>)&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">delete</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">delete </CODE><CODECLASS="replaceable"><I>array</I></CODE>[<CODECLASS="replaceable"><I>element</I></CODE>]<CODECLASS="literal"> </CODE>Delete <CODECLASS="replaceable"><I>element</I></CODE> of <CODECLASS="replaceable"><I>array</I></CODE>. (<EMCLASS="emphasis">nawk</EM>)<ACLASS="indexterm"NAME="AUTOID-37664"></A>&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">do</CODE></DT><DDCLASS="listitem"><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"><CODECLASS="literal">do</CODE>     <CODECLASS="replaceable"><I>body</I></CODE><CODECLASS="literal">while (</CODE><CODECLASS="replaceable"><I>expr</I></CODE><CODECLASS="literal">)</CODE></PRE></BLOCKQUOTE>Looping statement.<ACLASS="indexterm"NAME="AUTOID-37677"></A>Execute statements in <CODECLASS="replaceable"><I>body</I></CODE>, then evaluate <CODECLASS="replaceable"><I>expr</I></CODE>.If <CODECLASS="replaceable"><I>expr</I></CODE> is true, execute <CODECLASS="replaceable"><I>body</I></CODE> again.More than one <CODECLASS="replaceable"><I>command</I></CODE> must be put inside braces (<CODECLASS="literal">{}</CODE>).(<EMCLASS="emphasis">nawk</EM>)&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">exit</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">exit</CODE>[<CODECLASS="replaceable"><I>expr</I></CODE>]Do not execute remaining instructions and do not read new input.<ACLASS="indexterm"NAME="AUTOID-37693"></A>ENDprocedure, if any, will be executed.The <CODECLASS="literal">expr</CODE>, if any, becomes <EMCLASS="emphasis">awk</EM>'s <SPANCLASS="link">exit status (<ACLASS="linkend"HREF="ch44_07.htm"TITLE="Exit Status of UNIX Processes ">44.7</A>)</SPAN>.&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">exp</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">exp(</CODE><CODECLASS="replaceable"><I>arg</I></CODE><CODECLASS="literal">)&#13;</CODE>Return the natural exponent of <CODECLASS="replaceable"><I>arg</I></CODE>.<ACLASS="indexterm"NAME="AUTOID-37707"></A>&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">for</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">for (</CODE>[<CODECLASS="replaceable"><I>init-expr</I></CODE>]<CODECLASS="literal">; </CODE>[<CODECLASS="replaceable"><I>test-expr</I></CODE>]<CODECLASS="literal">; </CODE>[<CODECLASS="replaceable"><I>incr-expr</I></CODE>]<CODECLASS="literal">)</CODE>    <CODECLASS="replaceable"><I>command</I></CODE>C-language-style looping construct.<ACLASS="indexterm"NAME="AUTOID-37722"></A>Typically, <CODECLASS="replaceable"><I>init-expr</I></CODE> assigns the initial value of a countervariable.<CODECLASS="replaceable"><I>test-expr</I></CODE> is a relational expression that is evaluated each timebefore executing the <CODECLASS="replaceable"><I>command</I></CODE>.When <CODECLASS="replaceable"><I>test-expr</I></CODE> is false, the loop is exited.<CODECLASS="replaceable"><I>incr-expr</I></CODE> is used to increment the counter variable after each pass.A series of <CODECLASS="replaceable"><I>command</I></CODE>smust be put within braces (<CODECLASS="literal">{}</CODE>).Example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">for (i = 1; i &lt;= 10; i++)     printf &quot;Element %d is %s.\n&quot;, i, array[i]</PRE></BLOCKQUOTE></P><PCLASS="para"></P></DD><DTCLASS="term"><CODECLASS="literal">for</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">for (</CODE><CODECLASS="replaceable"><I>item </I></CODE><CODECLASS="literal">in </CODE><CODECLASS="replaceable"><I>array</I></CODE><CODECLASS="literal">)</CODE>     <CODECLASS="replaceable"><I>command</I></CODE>For each <CODECLASS="replaceable"><I>item</I></CODE> in an associative <CODECLASS="replaceable"><I>array</I></CODE>, do<CODECLASS="replaceable"><I>command</I></CODE>.More than one <CODECLASS="replaceable"><I>command</I></CODE> must be put inside braces (<CODECLASS="literal">{}</CODE>).Refer to each element of the array as <CODECLASS="replaceable"><I>array</I></CODE><CODECLASS="literal">[</CODE><CODECLASS="replaceable"><I>item</I></CODE><CODECLASS="literal">]</CODE>.&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">getline</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">getline </CODE>[<CODECLASS="replaceable"><I>var</I></CODE>][<CODECLASS="literal">&lt;</CODE><CODECLASS="replaceable"><I>file</I></CODE>]        or<CODECLASS="replaceable"><I>command </I></CODE><CODECLASS="literal">| getline </CODE>[<CODECLASS="replaceable"><I>var</I></CODE>]Read next line of input.Original <EMCLASS="emphasis">awk</EM> does not support the syntaxto open multiple input streams.The first form reads input from <CODECLASS="replaceable"><I>file</I></CODE>,and the second form reads the standard output of a UNIX <CODECLASS="replaceable"><I>command</I></CODE>.Both forms read one line at a time, and each timethe statement is executed it gets the next lineof input.The line of input is assigned to <CODECLASS="literal">$0</CODE>,and it is parsed into fields, setting <EMCLASS="emphasis">NF</EM>,<EMCLASS="emphasis">NR</EM>, and <EMCLASS="emphasis">FNR</EM>.If <CODECLASS="replaceable"><I>var</I></CODE> is specified, the result is assignedto <CODECLASS="replaceable"><I>var</I></CODE> and the <CODECLASS="literal">$0</CODE> is not changed.Thus, ifthe result is assigned to a variable, thecurrent line does not change.<EMCLASS="emphasis">getline</EM> is actually a function and it returns 1 if itreads a record successfully, 0 if end-of-file isencountered, and -1 if for some reason it isotherwise unsuccessful. (<EMCLASS="emphasis">nawk</EM>)&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">gsub</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">gsub(</CODE><CODECLASS="replaceable"><I>r</I></CODE><CODECLASS="literal">,</CODE><CODECLASS="replaceable"><I>s</I></CODE>[<CODECLASS="literal">,</CODE><CODECLASS="replaceable"><I>t</I></CODE>]<CODECLASS="literal">)</CODE>Globally substitute <CODECLASS="replaceable"><I>s</I></CODE> for each match of the<ACLASS="indexterm"NAME="AUTOID-37791"></A>regular expression <CODECLASS="replaceable"><I>r</I></CODE> in the string <CODECLASS="replaceable"><I>t</I></CODE>.Returnthe number of substitutions.If <CODECLASS="replaceable"><I>t</I></CODE> is not supplied,defaults to <CODECLASS="literal">$0</CODE>. (<EMCLASS="emphasis">nawk</EM>)&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">if</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">if (</CODE><CODECLASS="replaceable"><I>condition</I></CODE><CODECLASS="literal">)</CODE></P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">      <CODECLASS="replaceable"><I>command</I></CODE>[<CODECLASS="literal">else</CODE>      <CODECLASS="replaceable"><I>command</I></CODE>]</PRE></BLOCKQUOTE></P><PCLASS="para">If <CODECLASS="replaceable"><I>condition</I></CODE> is true, do <CODECLASS="replaceable"><I>command(s)</I></CODE>, otherwise do<ACLASS="indexterm"NAME="AUTOID-37814"></A><CODECLASS="replaceable"><I>command(s)</I></CODE> in <EMCLASS="emphasis">else</EM> clause (if any).<CODECLASS="replaceable"><I>condition</I></CODE> can be an expression that uses any of the relational operators <CODECLASS="literal">&lt;</CODE>, <CODECLASS="literal">&lt;=</CODE>, <CODECLASS="literal">==</CODE>, <CODECLASS="literal">!=</CODE>, <CODECLASS="literal">&gt;=</CODE>, or <CODECLASS="literal">&gt;</CODE>, as well asthe pattern-matching operators <CODECLASS="literal">~</CODE> or <CODECLASS="literal">!~</CODE>(e.g., <CODECLASS="literal">if&nbsp;($1&nbsp;~&nbsp;/[Aa].*[Zz]/)</CODE>).A series of <CODECLASS="replaceable"><I>command</I></CODE>s must be put within braces (<CODECLASS="literal">{}</CODE>).</P></DD><DTCLASS="term"><CODECLASS="literal">index</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">index(</CODE><CODECLASS="replaceable"><I>str</I></CODE><CODECLASS="literal">,</CODE><CODECLASS="replaceable"><I>substr</I></CODE><CODECLASS="literal">)</CODE>Return position of first substring <CODECLASS="replaceable"><I>substr</I></CODE> in string <CODECLASS="replaceable"><I>str</I></CODE><ACLASS="indexterm"NAME="AUTOID-37842"></A>or 0 if not found.&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">int</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">int(</CODE><CODECLASS="replaceable"><I>arg</I></CODE><CODECLASS="literal">)</CODE>Return integer value of <CODECLASS="replaceable"><I>arg</I></CODE>.<ACLASS="indexterm"NAME="AUTOID-37853"></A>&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">length</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">length(</CODE><CODECLASS="replaceable"><I>arg</I></CODE><CODECLASS="literal">)</CODE>Return the length of <CODECLASS="replaceable"><I>arg</I></CODE>.<ACLASS="indexterm"NAME="AUTOID-37864"></A>&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">log</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">log(</CODE><CODECLASS="replaceable"><I>arg</I></CODE><CODECLASS="literal">)</CODE>Return the natural logarithm of <CODECLASS="replaceable"><I>arg</I></CODE>.<ACLASS="indexterm"NAME="AUTOID-37875"></A>&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">match</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">match(</CODE><CODECLASS="replaceable"><I>s</I></CODE><CODECLASS="literal">,</CODE><CODECLASS="replaceable"><I>r</I></CODE><CODECLASS="literal">)</CODE>Function that matches the pattern, specified by the regular expression<ACLASS="indexterm"NAME="AUTOID-37887"></A><CODECLASS="replaceable"><I>r</I></CODE>, in the string <CODECLASS="replaceable"><I>s</I></CODE> and returns either the position in<CODECLASS="replaceable"><I>s</I></CODE> where the match begins or 0 if no occurrences are found.Sets the values of <EMCLASS="emphasis">RSTART</EM> and <EMCLASS="emphasis">RLENGTH</EM>. (<EMCLASS="emphasis">nawk</EM>)&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">next</CODE></DT><DDCLASS="listitem"><PCLASS="para">Read next input line and start new cycle through pattern/proceduresstatements.<ACLASS="indexterm"NAME="AUTOID-37900"></A>&#13;</P></DD><DTCLASS="term"><CODECLASS="literal">print</CODE></DT><DDCLASS="listitem"><PCLASS="para"><CODECLASS="literal">print </CODE>[<CODECLASS="replaceable"><I>args</I></CODE>] [<CODECLASS="replaceable"><I>destination</I></CODE>]Print <CODECLASS="replaceable"><I>args</I></CODE> on output, followed by a newline.<ACLASS="indexterm"NAME="AUTOID-37911"></A><CODECLASS="replaceable"><I>args</I></CODE> is usually one or more fields,but may also be one or more of the predefined variables&nbsp;- orarbitrary expressions.If no <CODECLASS="replaceable"><I>args</I></CODE> are given, prints <CODECLASS="literal">$0</CODE

⌨️ 快捷键说明

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