September 15 awk Summary

Source: Internet
Author: User

Awk is the report generator

Awk is the original Aho,weinberger,kernighan three initials

awk is a symbolic link pointing to gawk

AWK is a separate programming language,

Mode: Similar address delimitation

$ A represents an entire line

$1$2$3$4, which represents each unit separated by a space

650) this.width=650; "title=" image "style=" border-right-width:0px;border-bottom-width:0px;border-top-width:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M01/73/85/wKiom1YADj6xcd5sAABcEAXrXVw004.jpg" width= "506" height= "136"/>

-F char is a delimiter

awk [Options] ' program ' file

awk [option] ' pattern{action} ' file

Supported variables:

Built-in variables, custom variables

Built-in variables:

FS: Field delimiter when entering

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/73/85/wKiom1YADj6BUrr2AADIDMwaJY4447.jpg" height= "144" />

Rs: Enter the rows separator

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/85/wKiom1YADj7y6vB3AABtxNlPH9Q273.jpg" height= "141" />

OFS: Field delimiter at output

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M01/73/85/wKiom1YADj_QCZqsAADLvfmKGoI815.jpg" height= "100" />

ORS: Output Rows Separator

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/73/85/wKiom1YADj-yi1OxAAFZXJIXPVo513.jpg" height= "108" />

NF: Number of fields in a row

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/85/wKiom1YADj-zpwm1AAD1hEnCU3k364.jpg" height= "264" />

NR: Number of lines in the file

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M01/73/85/wKiom1YADkDRLMEuAAEaEwXrk0I308.jpg" height= "297" />

FNR: Displays the line number of each file

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/73/85/wKiom1YADkCB4GRSAAFymnkP1l8164.jpg" height= "314" />

Awk–f: ' {print $, $NF} '/etc/passwdd equivalent to the command below

Awk–v fs=: ' {print $, $NF} '/etc/passwd



Custom variables

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/85/wKiom1YADkDjkwOwAADE6RkLQnU412.jpg" height= "180" />

printf command:

printf format,item1,item2

The options for format are:

%c: ASCII code for displaying characters

%d,%i: Display Decimal

%e,%e: Scientific and technological law shows numerical value

%f: Display string

%g,%g: Displaying values in scientific or technical law format or floating-point number format

%s: Display string

%u: Show unsigned integers

Percent: show% itself

Modifier:

#: Width

-Align Left

+ Display numeric symbols

. #取精度值

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "Http://s3.51cto.com/wyfs02/M01/73/85/wKiom1YADkHDzrGCAAB8ye1dykQ770.jpg" height= "86"/ >

Note: Print does not show the meaning of%d, only the characters are displayed

Arithmetic operations: +,-,*,/,+=,-=,*=,/=

If you are =, write/=/

Comparison operators:

<

<=

>

>=

==

!=

~ Left string can match right mode to True

!~ against the previous command

Three-mesh operator:

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "Http://s3.51cto.com/wyfs02/M02/73/83/wKioL1YAEH-CfBNIAAB9v4vKUa4371.jpg" height= "109" />

Pattern, Mode:

1. Regular:/pattern/

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/83/wKioL1YAEH-j7XYPAAB2HMKcQMw314.jpg" height= "74"/ >

2. Expression:

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M01/73/83/wKioL1YAEH_xfx6kAACvrLl55rA832.jpg" height= "224" />

3, line range, address bound startline endline, etc., with NR to make judgments

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/73/83/wKioL1YAEIDzJiBWAACyepXKPtc289.jpg" height= "77"/ >

4, Begin/end Special mode, indicating that before (BEGIN) or after (END) Run 1 times

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "Http://s3.51cto.com/wyfs02/M02/73/83/wKioL1YAEIDgJXb4AABsyfUAd-g489.jpg" height= "99"/ >

5, empty mode, match any row, default mode

Action

1. Expression

2, the control statement If-else,

if (condition) {then Body}else{else body}

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/85/wKiom1YADkKjNDqoAACAPxeWFJY481.jpg" height= "91"/ >

Do-while

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "Http://s3.51cto.com/wyfs02/M01/73/85/wKiom1YADkOSau3LAABl-0Ajov8427.jpg" height= "101" />

The cycle of death.

While

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/73/85/wKiom1YADkPw2gBrAAB_5aHFPNw468.jpg" height= "266" />

For

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/83/wKioL1YAEIGg6NL3AAG50bC2Ylc257.jpg" height= "254" />

Case

3. Combined statement

4. Input statement

5. Output Statement print,printf

Loop control: Break,continue,next

Next, advance into the next line of processing!!

Array:

Legacy Arrays: Index starting from 1

Associative arrays

for (var in array), array is index

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/83/wKioL1YAEILAj9HOAAEY3LY3m2o161.jpg" height= "133" />

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/73/85/wKiom1YADkSisLdQAACGz1NS3po664.jpg" height= "70"/ >

This usage is very common and counts the number of different names in the same field

Built-in functions:

Length (string), string length

Split (target string, separated position, delimiter) delimited string

SUBSTR Fetch substring

September 15 awk Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.