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

awk - Unix, Linux Command---reference

发布时间:2021-01-26 03:28:47 所属栏目:Linux 来源:网络整理
导读: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-
<tr>
<td>

BEGIN 
END 
/regular expression/ 
relational expression 
pattern && pattern 
pattern || pattern 
pattern ? pattern : pattern 
(pattern) 
! pattern 
pattern1,pattern2 
BEGIN?and?END?are two special kinds of patterns which are not tested against the input. The action parts of all?BEGIN?patterns are merged as if all the statements had been written in a single?BEGIN?block. They are executed before any of the input is read. Similarly,all the?END?blocks are merged,and executed when all the input is exhausted (or when an?exit?statement is executed).?BEGIN?and?END?patterns cannot be combined with other patterns in pattern expressions.?BEGIN?and?END?patterns cannot have missing action parts.

For?/regular expression/?patterns,the associated statement is executed for each input record that matches the regular expression. Regular expressions are the same as those in?egrep(1),and are summarized below.

A?relational expression?may use any of the operators defined below in the section on actions. These generally test whether certain fields match certain regular expressions.

The?&&,?||,and?!?operators are logical AND,logical OR,and logical NOT,as in C. They do short-circuit evaluation,also as in C,and are used for combining more primitive pattern expressions. As in most languages,parentheses may be used to change the order of evaluation.

The??:?operator is like the same operator in C. If the first pattern is true then the pattern used for testing is the second pattern,otherwise it is the third. Only one of the second and third patterns is evaluated.

The?pattern1,?pattern2?form of an expression is called a?range pattern. It matches all input records starting with a record that matches?pattern1,and continuing until a record that matches?pattern2,inclusive. It does not combine with any other sort of pattern expression.

Regular Expressions

Regular expressions are the extended kind found in?egrep. They are composed of characters as follows:

Multiple statements may be put on one line by separating them with a ‘‘;’’. This applies to both the statements within the action part of a pattern-action pair (the usual case),and to the pattern-action statements themselves.

Patterns

AWK?patterns may be one of the following:

<table class="src" cellspacing="5" cellpadding="5">

cc.cc.including?newline.abc...] abc....abc...] abc....r1|r2r1?or?r2.r1r2r1,and then?r2.r+ r’s.r* r’s.r? r’s.r) r.r{n}?r{n,}?r{n,m} interval expression. If there is one number in the braces,the preceding regular expression?r?is repeated?n?times. If there are two numbers separated by a comma,?r?is repeated?n?to?m?times. If there is one number followed by a comma,then?r?is repeated at least?n?times.

Interval expressions are only available if either?--posix?or?--re-interval?is specified on the command line.

</td>

</tr>
<tr valign="top">
<td>y</td>
<td valign="bottom">matches the empty string at either the beginning or the end of a word.</td>

</tr>
<tr valign="top">
<td>B</td>
<td valign="bottom">matches the empty string within a word.</td>

</tr>
<tr valign="top">
<td>&;</td>
<td valign="bottom">matches the empty string at the beginning of a word.</td>

</tr>
<tr valign="top">
<td>></td>
<td valign="bottom">matches the empty string at the end of a word.</td>

</tr>
<tr valign="top">
<td>w</td>
<td valign="bottom">matches any word-constituent character (letter,digit,or underscore).</td>

</tr>
<tr valign="top">
<td>W</td>
<td valign="bottom">matches any character that is not word-constituent.</td>

</tr>
<tr valign="top">
<td>‘</td>
<td valign="bottom">matches the empty string at the beginning of a buffer (string).</td>

</tr>
<tr valign="top">
<td>’</td>
<td valign="bottom">matches the empty string at the end of a buffer.</td>

</tr>

The escape sequences that are valid in string constants (see below) are also valid in regular expressions.

(编辑:威海站长网)

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

Description
热点阅读