命令linux命令awk整理(Linux command awk collation)

awk命令  时间:2021-02-12  阅读:()

l inux命令awk整理Linux command awk collationFormat:

Standard format: awk {' [BEGIN} , pre initialized or sentencepattern matching operation statement [END] {} {} ]' <filename >end statement

Awk script:

Close to awk as a programming language, can write scripts toperform, only need to place a statement to explain the script(after the first line of the script #!) with the location ofthe awk, the awk can be as a script executable programexecution.

Vari abl e:

$0: current entire line content.

The line delimiter entered by ORS: (default is newline)Line delimiter for RS: output (default is newline)

The number of rows that NR: has processed (+1 per row)NF: the number of fields in the current row (how many is thelast $?)?

FS: field delimiter

Number of ARGC: command l ine arguments

ARGV: command line parameter array (subscript starts at 0)Relation operation:

Less than <:

<=: is less than or equal to

==: equals

=: is not equal to!

More than >:

~: regular expression matching

~: does not match the regular expression!

A, b:c: , three element expression, conforms to the a condition,performs B, otherwise executes C. Equivalent to "if (a) {b";"}else{c"; }"

Arithmetic operation:

Floating point arithmetic.

Logical operation:

"&&", "| |" and "!" (respectively, with or without) .

Matching range:

"/a/, /b/" (from the matching/a/ to/b/, and SED) , different,awk is not only the first match, when matched to the B afterthe stop, then, a will start again, until then, to B and thenstop, wait, a. . . . . .

"NR==2, NR==5", from the second line to the fifth line.Assignment operation:

A =: is a two assignment, is a comparison of the sameRegular expression:

Do not support the "\<", "\>", "(\ \)", "\{\}"

Program control instruction:

Next: reads the next line of text and starts the script againfrom scratch.

Exit: jumps out of all operations and executes the END segmentdirectly.

Internal function:

Getline successfully read a line after the return of 1, readto the end of the file after the return of 0, but if the filedoes not exist, it will return-1, if the getline in the "while()", may be because the return -1 into the dead cycle.

Internal function (string) :

Split: divides strings into fields by field separators,respectively, into arrays.

Command format: split (string, array, f ield delimiter)Or use the default field delimiter (the FS parameter in awk) :Split (string, array)

The array generated by the function; the first element has anindex of 1.

Delete: removes array elements

Command format: delete< array name >[] .

Sub: is much like "s/a/b/" in sed, which turns the childsubstring into a subsequence.

Command format: sub (regular expression, alternate string)Sub (regular expression, substitution string, target location)The regular expression "/ /" (including slash) .

Replace strings with "" "(double quotes) , including. (allstrings should be enclosed indouble quotes, not single quotes)

The target position is generally similar to the field positionof "$1".

Sub replaces only the first match, similar to "s/a/b/""Gsub: is similar to "s/a/b/g", global replacement.

Command format: gsub (regular expression, alternate string)Gsub (regular expression, substitution string, targetlocation)

Index: returns the location of the substring that firstappeared in the string

Command format: index (string, substring) (string, substring,printed directly, enclosed in double quotes)

Length: returns string length

Command format: length (string) (string is printed directly,enclosed in double quotes)

Match: returns the position in the string that matches theregular expression for the first time

Command format: match (string, regular expression) (string isprinted directly, enclosed in double quotes)

Use

Awk will assign the current row to the variable "$0" first"Awk differs from sed, although each time a row is read into thecache, it is cut by the delimiter defined by the"FS"parameter.When outputting, it will also use the "OFS"parameter to changethe separator when outputting.

The "OFMT" parameter is used to set the format of the outputdigits.

Use the "-F" parameter to change the delimiter, if you usemultiple symbols to do separate, need to use "[]" inparentheses.

Example: "awk -F '\t]' " (when awk encounters spaces and tabsare translated into a delimiter)

The awk command is divided into two parts, the mode and theoperation, and the model is equivalent to the built-in if. . . . . .Then".

Similar to the SED address, is the implementation of theprovisions of the operation behind what time, and the operationmust be included in the "{}" (braces) and follow mode. Patternsnever appear in curly braces.

The matching character"~"wave number is used to define matchesin the pattern.

Example: "awk'$1 ~ /Bill/' " (matches Bill in the first field)

"Awk'$1. . . ~ /Bill/' " (Bill is not found in the first field)When performing string operations, strings must be enclosed in"" "" (double quotes) , and single quotation marks do not!Example: "awk'$1 =" CT "' " (the first field for CT)

Awk' {pr int ($1 > 5? "High": "low"} ' )

Awk variables are initialized without defining type, and awkautomatically changes the type of the variable depending on thecontext.

Awk variables can be named with letters and numbers, but theycannot begin with numbers.

The awk command can contain more than one set of patterns andoperations. With {in} respectively.

Awk can be added in the "BEGIN" command, the command in thecommand in the execution of read text (no text will read beforeexecution) , generally used for variable initialization orprint the first page.

In awk, you can add the "END" command section that executesafter processing all the text.

In awk, if you want to redirect the results of the commandexecution, you need to add "" "" "" "" (double quotes) to theredirection file name

Example: "awk print $1" test ">' {} ' " (the first field outputto test file)

In awk, through the "getline" command (enclosed in doublequotes) , enter information (rather than files) from the pipe,the standard input.

Example: "awk"LS"' { | getline a; print a} ' " (each matching modeoutput line)

Printf format "printf"%-12s "a" (the percent is used to specifythe output format settings, minus is left aligned, 12 is thelength of S is a string, a is printed variable)

Be careful

Open the pipeline in awk, must use the pipe symbol "|" afterthe same name to close thepipeline. Otherwise thepipelinewillremain open, behind the input will also be sent to an rvaluepipeline.

"Awk" LS "' { | getline a; print a} ' ' {close (getline a) } ' "The variable loop in the "for" loop in awk can only use onev ar i ab l e

"For (i=0; i<10; i++)" (cannot declare two variables in the samefor)

Arrays in awk use hash storage, so direct output arrays are not

necessarily indexed.

Arrays in awk can be indexed in strings, and strings need tobe enclosed in "" "double" quotes.

Printed arrays indexed by strings can be printed with for XXin < < > > to print all elements of an array.

Make sure that the entire awk command is enclosed in singlequotes.

Make sure all quotation marks appear in pairs in the command.Make sure you enclose the action statement with curly bracesand enclose conditional statements with parentheses.

Awk supports multidimensional arrays

See the 223 page

傲游主机38.4元起,韩国CN2/荷兰VPS全场8折vps香港高防

傲游主机怎么样?傲游主机是一家成立于2010年的老牌国外VPS服务商,在澳大利亚及美国均注册公司,是由在澳洲留学的害羞哥、主机论坛知名版主组长等大佬创建,拥有多家海外直连线路机房资源,提供基于VPS主机和独立服务器租用等,其中VPS基于KVM或者XEN架构,可选机房包括中国香港、美国洛杉矶、韩国、日本、德国、荷兰等,均为CN2或者国内直连优秀线路。傲游主机提供8折优惠码:haixiuge,适用于全...

云步云72.5元/月起云服务器,香港安畅/葵湾/将军澳/沙田/大浦CN2机房,2核2G5M

云步云怎么样?云步云是创建于2021年的品牌,主要从事出售香港vps、美国VPS、日本VPS、香港独立服务器、香港站群服务器等,机房有香港、美国、日本东京等机房,目前在售VPS线路有CN2+BGP、CN2 GIA,香港的线路也是CN2直连大陆,该公司旗下产品均采用KVM虚拟化架构。目前,云步云提供香港安畅、沙田、大浦、葵湾、将军澳、新世界等CN2机房云服务器,2核2G5M仅72.5元/月起。点击进...

搬瓦工VPS:新增荷兰机房“联通”线路的VPS,10Gbps带宽,可在美国cn2gia、日本软银、荷兰“联通”之间随意切换

搬瓦工今天正式对外开卖荷兰阿姆斯特丹机房走联通AS9929高端线路的VPS,官方标注为“NL - China Unicom Amsterdam(ENUL_9)”,三网都走联通高端网络,即使是在欧洲,国内访问也就是飞快。搬瓦工的依旧是10Gbps带宽,可以在美国cn2 gia、日本软银与荷兰AS9929之间免费切换。官方网站:https://bwh81.net优惠码:BWH3HYATVBJW,节约6...

awk命令为你推荐
免费企业邮局付费企业邮箱哪个好?便宜又好用的邮箱打不开怎么办126邮箱打不开怎么办中国论坛大全甘肃论坛都有哪些?9flash怎么使用ePSXe啊?滚动代码来回滚动代码godaddyGodaddy域名怎么接受2012年正月十五2012年正月十五上午9点27分出生的女孩儿五行缺什么,命怎么样如何清理ie缓存怎么清除IE缓存网站排名靠前怎样才能做好一个网站?让网站排名靠前?新手求解怎么在图片上写文字如何在图片上写文字
个人注册域名 国外vps 浙江vps 西安服务器 flashfxp怎么用 westhost 秒解服务器 uk2 流媒体服务器 回程路由 牛人与腾讯客服对话 湖南服务器托管 免费防火墙 东莞数据中心 稳定免费空间 免费网页申请 789电视剧 海外空间 百度云空间 免费网络 更多