加入收藏 | 设为首页 | 会员中心 | 我要投稿 温州站长网 (https://www.0577zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

awk - Unix, Linux Command---reference

发布时间:2021-01-30 02:45:05 所属栏目:Linux 来源:网络整理
导读:副标题#e# http://www.tutorialspoint.com/unix_commands/awk.htm gawk - pattern scanning and processing language gawk?[?POSIX?or?GNU?style options ]?-f? program-file ?[?--?] file ...?gawk?[?POSIX?or?GNU?style options ] [?--?]? program-text ?

<tr>
<th width="25%">Tag

gawk,or the program source).</tr>
<tr valign="top">
<td>ARGIND</td>
<td valign="bottom">The index in?ARGV?of the current file being processed.</td>

</tr>
<tr valign="top">
<td>ARGV</td>
<td valign="bottom">Array of command line arguments. The array is indexed from 0 to?ARGC?- 1. Dynamically changing the contents of?ARGV?can control the files used for data.</td>

</tr>
<tr valign="top">
<td>BINMODE</td>
<td valign="bottom">On non-POSIX systems,specifies use of ‘‘binary’’ mode for all file I/O. Numeric values of 1,2,or 3,specify that input files,output files,or all files,respectively,should use binary I/O. String values of?"r",or?"w"?specify that input files,or output files,should use binary I/O. String values of?"rw"?or"wr"?specify that all files should use binary I/O. Any other string value is treated as?"rw",but generates a warning message.</td>

</tr>
<tr valign="top">
<td>CONVFMT</td>
<td valign="bottom">The conversion format for numbers,?"%.6g",by default.</td>

(编辑:温州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

For each record in the input,?gawk?tests to see if it matches any?pattern?in the?AWKprogram. For each pattern that the record matches,the associated?action?is executed. The patterns are tested in the order they occur in the program.

Finally,after all the input is exhausted,?gawk?executes the code in the?END?block(s) (if any).

AWK?variables are dynamic; they come into existence when they are first used. Their values are either floating-point numbers or strings,or both,depending upon how they are used.?AWK?also has one dimensional arrays; arrays with multiple dimensions may be simulated. Several pre-defined variables are set as a program runs; these will be described as needed and summarized below.

Records

Normally,records are separated by newline characters. You can control how records are separated by assigning values to the built-in variable?RS. If?RS?is any single character,that character separates records. Otherwise,?RS?is a regular expression. Text in the input that matches this regular expression separates the record. However,in compatibility mode,only the first character of its string value is used for separating records. If?RS?is set to the null string,then records are separated by blank lines. WhenRS?is set to the null string,the newline character always acts as a field separator,in addition to whatever value?FS?may have.

Fields

As each input record is read,?gawk?splits the record into?fields,using the value of the?FSvariable as the field separator. If?FS?is a single character,fields are separated by that character. If?FS?is the null string,then each individual character becomes a separate field. Otherwise,?FS?is expected to be a full regular expression. In the special case thatFS?is a single space,fields are separated by runs of spaces and/or tabs and/or newlines. (But see the discussion of?--posix,below).?NOTE:?The value of?IGNORECASE(see below) also affects how fields are split when?FS?is a regular expression,and how records are separated when?RS?is a regular expression.

If the?FIELDWIDTHS?variable is set to a space separated list of numbers,each field is expected to have fixed width,and?gawk?splits up the record using the specified widths. The value of?FS?is ignored. Assigning a new value to?FS?overrides the use ofFIELDWIDTHS,and restores the default behavior.

Each field in the input record may be referenced by its position,?$1,?$2,and so on.?$0?is the whole record. Fields need not be referenced by constants:

n = 5?print $n

prints the fifth field in the input record.

The variable?NF?is set to the total number of fields in the input record.

References to non-existent fields (i.e. fields after?$NF) produce the null-string. However,assigning to a non-existent field (e.g.,?$(NF+2) = 5) increases the value of?NF,creates any intervening fields with the null string as their value,and causes the value of?$0?to be recomputed,with the fields being separated by the value of?OFS. References to negative numbered fields cause a fatal error. Decrementing?NF?causes the values of fields past the new value to be lost,and the value of?$0?to be recomputed,with the fields being separated by the value of?OFS.

Assigning a value to an existing field causes the whole record to be rebuilt when?$0?is referenced. Similarly,assigning a value to?$0?causes the record to be resplit,creating new values for the fields.

Built-in Variables

Gawk’s built-in variables are:

<table class="src" border="1" cellspacing="0" cellpadding="5">

Description
热点阅读