加入收藏 | 设为首页 | 会员中心 | 我要投稿 温州站长网 (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 ?
In compatibility mode,any other options are flagged as invalid,but are otherwise ignored. In normal operation,as long as program text has been supplied,unknown options are passed on to the?AWK?program in the?ARGV?array for processing. This is particularly useful for running?AWK?programs via the ‘‘#!’’ executable interpreter mechanism.

An?AWK?program consists of a sequence of pattern-action statements and optional function definitions.

pattern?{?action statements?}?function?name(parameter list) {?statements?}

Gawk?first reads the program source from the?program-file(s) if specified,from arguments to?--source,or from the first non-option argument on the command line. The?-f?and?--source?options may be used multiple times on the command line.?Gawk?reads the program text as if all the?program-files and command line source texts had been concatenated together. This is useful for building libraries of?AWK?functions,without having to include them in each new?AWK?program that uses them. It also provides the ability to mix library functions with command line programs.

The environment variable?AWKPATH?specifies a search path to use when finding source files named with the?-f?option. If this variable does not exist,the default path is".:/usr/local/share/awk". (The actual directory may vary,depending upon how?gawkwas built and installed.) If a file name given to the?-f?option contains a ‘‘/’’ character,no path search is performed.

Gawk?executes?AWK?programs in the following order. First,all variable assignments specified via the?-v?option are performed. Next,?gawk?compiles the program into an internal form. Then,?gawk?executes the code in the?BEGIN?block(s) (if any),and then proceeds to read each file named in the?ARGV?array. If there are no files named on the command line,?gawk?reads the standard input.

If a filename on the command line has the form?var=val?it is treated as a variable assignment. The variable?var?will be assigned the value?val. (This happens after anyBEGIN?block(s) have been run.) Command line variable assignment is most useful for dynamically assigning values to the variables?AWK?uses to control how input is broken into fields and records. It is also useful for controlling state if multiple passes are needed over a single data file.

If the value of a particular element of?ARGV?is empty (""),?gawk?skips over it.

(编辑:温州站长网)

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

</tr>
<tr valign="top">
<td width="1%">?</td>
<td>Send profiling data to?prof_file. The default is?awkprof.out. When run with?gawk,the profile is just a ‘‘pretty printed’’ version of the program. When run with?pgawk,the profile contains execution counts of each statement in the program in the left margin and function call counts for each user-defined function.</td>

</tr>
<tr valign="top">
<td colspan="2">
-W re-interval?--re-interval
</td>

</tr>
<tr valign="top">
<td width="1%">?</td>
<td>Enable the use of?interval expressions?in regular expression matching (see?<a href="http://www.tutorialspoint.com/#16"&gt;Regular Expressions,below). Interval expressions were not traditionally available in the?AWKlanguage. The?POSIX?standard added them,to make?awk?andegrep?consistent with each other. However,their use is likely to break old?AWK?programs,so?gawk?only provides them if they are requested with this option,or when?--posix?is specified.</td>

</tr>
<tr valign="top">
<td colspan="2">
-W source?program-text?--source?program-text
</td>

</tr>
<tr valign="top">
<td width="1%">?</td>
<td>Use?program-text?as?AWK?program source code. This option allows the easy intermixing of library functions (used via the?-fand?--file?options) with source code entered on the command line. It is intended primarily for medium to large?AWK?programs used in shell scripts.</td>

</tr>
<tr valign="top">
<td colspan="2">
-W version?--version
</td>

</tr>
<tr valign="top">
<td width="1%">?</td>
<td>Print version information for this particular copy of?gawk?on the standard output. This is useful mainly for knowing if the current copy of?gawk?on your system is up to date with respect to whatever the Free Software Foundation is distributing. This is also useful when reporting bugs. (Per the?GNU Coding Standards,successful exit.)</td>

</tr>
<tr valign="top">
<td>--</td>
<td valign="bottom">Signal the end of options. This is useful to allow further arguments to the?AWK?program itself to start with a ‘‘-’’. This is mainly for consistency with the argument parsing convention used by most other?POSIX?programs.</td>

</tr>

热点阅读