Awk's "two" explanations

Source: Internet
Author: User

As a powerful text processing tool, awk is essential for our daily work.

Basic syntax for awk:

awk [option parameter] ' script ' Var=value file or

awk [option parameter]-F scriptfile var=value file

Mans awk

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6B/BB/wKioL1U15Ijj8SzuAAE8OzgECjg908.jpg "title=" 1.png " alt= "Wkiol1u15ijj8szuaae8ozgecjg908.jpg"/>

Basic parameter Description :

-F: Specifies the file separation domain,

-V Var=value or--asign var=value: Assigns a user-defined variable

-MF nnn AND-MR nnn: It's no use at the moment. You can do it yourself Google

-W compact,-w Traditional: Running awk in compatibility mode, in fact awk and gawk are almost exactly the same.

-W copyleft,-w Copyright: Print short, copyrighted information.

-W help,-w usage: Prints the help information for awk.

-W Lint or--lint: Prints structural warnings that cannot be ported to traditional UNIX platforms.

-W POSIX: Turns on compatibility mode with limited, unrecognized:/x, function keyword, func, swap sequence, and when FS is a space, the new row is used as a domain delimiter; flush is not valid.

-W Re-interval: Allows the use of interval regular expressions.

-W Source Program-text: Use Program-text as the source code and can be used in combination with the-f command.

-W version: Prints the bug version information.

Usage: Here I have a text file Test.txt, which reads as follows

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6B/C0/wKiom1U166mjy4ZVAACYczlQ_MY202.jpg "title=" 2.png " alt= "Wkiom1u166mjy4zvaacyczlq_my202.jpg"/>

awk defaults to a space or tab as the delimiter.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6B/C0/wKiom1U17DySuFCMAACIi2I1eW4484.jpg "title=" 3.png " alt= "Wkiom1u17dysufcmaacii2i1ew4484.jpg"/>

Try to, as a delimiter.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6B/BB/wKioL1U17geQjP6MAAC56yLvrro537.jpg "title=" 4.png " alt= "Wkiol1u17geqjp6maac56ylvrro537.jpg"/>

The above command is equivalent to: awk ' BEGIN {fs= ', '} {print $1,$4} ' Test.txt ' This is the use of built-in variables '

Use multiple separators, divide the spaces first, and then use "," to split the split results.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/BC/wKioL1U18QrCa64eAACIsUUXTaI609.jpg "title=" 5.png " alt= "Wkiol1u18qrca64eaacisuuxtai609.jpg"/>

awk setting variable "can specify multiple variables"

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6B/C0/wKiom1U18NPizbqtAAEJdte_WCY098.jpg "title=" 6.png " alt= "Wkiom1u18npizbqtaaejdte_wcy098.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/C0/wKiom1U1-AmgN6SmAAF9bHRybBc496.jpg "title=" 7.png " alt= "Wkiom1u1-amgn6smaaf9bhrybbc496.jpg"/>

awk sequence number nr, which matches the line number of the text.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6B/BC/wKioL1U1_PjCfpUdAAC6LmMdf38596.jpg "style=" float: none; "title=" 8.png "alt=" Wkiol1u1_pjcfpudaac6lmmdf38596.jpg "/>

AWK Specifies the output separator symbol.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6B/C1/wKiom1U1-53CHegcAACt7cByeBk036.jpg "style=" float: none; "title=" 9.png "alt=" Wkiom1u1-53chegcaact7cbyebk036.jpg "/>

Regular use

Match $ contains "th", and print $2,$4, "~" symbol is the matching regular, representing the pattern start,//is to match the pattern

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/C1/wKiom1U1_GqR-LRfAAB16RMPolA886.jpg "title=" 10.png "alt=" Wkiom1u1_gqr-lrfaab16rmpola886.jpg "/>

Output rows containing "is"

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/BD/wKioL1U2AAST_fEiAACzYitM-Ek013.jpg "style=" float: none; "title=" 11.png "alt=" Wkiol1u2aast_feiaaczyitm-ek013.jpg "/>

How to ignore uppercase and lowercase

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/C1/wKiom1U1_qnARmKaAACTAEnujOU704.jpg "style=" float: none; "title=" 12.png "alt=" Wkiom1u1_qnarmkaaactaenujou704.jpg "/>

Take the anti-operation, a bit like the way grep is expressed.

Ignores case, matching the first column is not a/th/row.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/BD/wKioL1U2AYegNb9cAAC7iGiTYXY356.jpg "title=" 13.png "alt=" Wkiol1u2ayegnb9caac7igityxy356.jpg "/>

Another way of writing

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/BD/wKioL1U2Am7C5IvlAAC-m0n4jbQ082.jpg "title=" 14.png "alt=" Wkiol1u2am7c5ivlaac-m0n4jbq082.jpg "/>

awk Script

awk script Two keywords: BEGIN and end[note is uppercase]

Begin{represents the statement before execution}

End{represents the statement after execution}

Where you can add a Process control statement [if while for break continue, etc.]

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6B/C3/wKiom1U2I-Pyd530AABoM9FJH4o474.jpg "title=" 15.png "alt=" Wkiom1u2i-pyd530aabom9fjh4o474.jpg "/>

Cond

Awk's "two" explanations

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.