Simple examples of Text Analysis Tool awk and text awk

Source: Internet
Author: User

Simple examples of Text Analysis Tool awk and text awk

Create a file: vim hi

 

Take 2nd fields and 3rd fields:

Awk '{print $2, $3}' hi note {}, CommaWill be converted to a space in the output.

 

Character Description:

 

Display the entire line:

 

 

Field separator:-F

 

Built-in variable: NF: number of fields. $ NF indicates the last field.

 

NR: number of rows

 

/Regular expression/: only the rows that can be matched by the pattern here are processed.

 

Backend: awk '! /^ John/{print $2} 'hi

 

The preceding statement indicates that if the third field is greater than or equal to 500, the first and third fields are used.

 

Determine whether the last field is/bin/bash. If yes, print the first and last fields.

 

Perform pattern matching

 

Cat hi

Match row range

 

Get row range:

 

If condition judgment statement: determines whether the value of the third field is greater than 500

 

Character replacement:

Echo "this is a test" | awk 'gsub ("test", "abd ")'

 

Cat hi

While loop:

 

NF indicates the number of fields in the current row. length is a function that obtains the character length of $ I.

 

Awk '/^ tom/{I = 1; while (I <= NF) {if (length ($ I)> = 4) {print $ I, length ($ I)}; I ++} 'hi

The if statement is nested in the while loop.

 

The preceding while statement can also be replaced by a for loop statement.

Awk '/tom/{for (I = 1; I <= NF; I ++) {print $ I, length ($ I)}' hi

 

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.