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

awk - Unix, Linux Command---reference

发布时间:2021-01-31 03:04:18 所属栏目: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>

CONVFMT = "%2.2f"
a = 12
b = a ""
the variable?b?has a string value of?"12"?and not?"12.00".

Gawk?performs comparisons as follows: If two variables are numeric,they are compared numerically. If one value is numeric and the other has a string value that is a ‘‘numeric string,’’ then comparisons are also done numerically. Otherwise,the numeric value is converted to a string and a string comparison is performed. Two strings are compared,of course,as strings. Note that the POSIX standard applies the concept of ‘‘numeric string’’ everywhere,even to string constants. However,this is clearly incorrect,andgawk?does not do this. (Fortunately,this is fixed in the next version of the standard.)

Note that string constants,such as?"57",are?not?numeric strings,they are string constants. The idea of ‘‘numeric string’’ only applies to fields,?getline?input,?FILENAME,ARGV?elements,?ENVIRON?elements and the elements of an array created by?split()that are numeric strings. The basic idea is that?user input,and only user input,that looks numeric,should be treated that way.

Uninitialized variables have the numeric value 0 and the string value "" (the null,or empty,string).

Octal and Hexadecimal Constants

Starting with version 3.1 of?gawk,?you may use C-style octal and hexadecimal constants in your AWK program source code. For example,the octal value?011?is equal to decimal9,and the hexadecimal value?0x11?is equal to decimal 17.

String Constants

String constants in?AWK?are sequences of characters enclosed between double quotes ("). Within strings,certain?escape sequences?are recognized,as in C. These are:

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


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

hex digitsdddcc.The escape sequences may also be used inside constant regular expressions (e.g.,?/[ tfnrv]/?matches whitespace characters).

In compatibility mode,the characters represented by octal and hexadecimal escape sequences are treated literally when used in regular expression constants. Thus,/a52b/?is equivalent to?/a*b/.

AWK?is a line-oriented language. The pattern comes first,and then the action. Action statements are enclosed in?{?and?}. Either the pattern may be missing,or the action may be missing,but,not both. If the pattern is missing,the action is executed for every single record of input. A missing action is equivalent to

{ print }

which prints the entire record.

(编辑:好传媒网)

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

When a string must be converted to a number,the conversion is accomplished usingstrtod(3). A number is converted to a string by using the value of?CONVFMT?as a format string for?sprintf(3),with the numeric value of the variable as the argument. However,even though all numbers in?AWK?are floating-point,integral values are?always?converted as integers. Thus,given

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

Description
热点阅读