Linux Common basic commands: The-awk mode usage of the Three Musketeers command (1)

Source: Internet
Author: User

Again, the awk basic syntax format:

awk [Options] ' Pattern {Action} ' file1 file2

The previous article discussed two types of pattern (BEGIN, END), and this article explores other pattern (pattern) usages again.

What is the pattern? A pattern is a matching condition that satisfies a condition and executes the subsequent action.

1, without any pattern of usage, called null mode

[Email protected]:~/linux/awkawk'{print}'   man Lisi

2, by the built-in variable NF, the row of the print column equals 3

[Email protected]:~/linux/awkcatlisi[ Email protected]:~/linux/awkawk'nf==3{print}'    Man

3, you can also use relational operators, relational operators, similar to most programming languages:

[Email protected]:~/linux/awk$Catghostwu.txt GHOSTWU - MansZhangsan ALisi[email protected]:~/linux/awk$awk '$1== "Ghostwu" {print}'ghostwu.txt GHOSTWU - Mans[email protected]:~/linux/awk$awk 'nf>1 "{print}"'ghostwu.txt GHOSTWU - MansZhangsan A

4, previously introduced by begin, End mode

[Email protected]:~/linux/awkawk'begin{print ' name ', ' age ', ' gender '} {print $, $ $, $ $} end{ Print "Package Sky", "Man"}' $ Man ' Lisi    $ Mans

Linux Common basic commands: The-awk mode usage of the Three Musketeers command (1)

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.