Linux basic--awk text analysis tools

Source: Internet
Author: User

Introduction

Awk is a powerful text analysis tool, with the search for grep and the editing of SED, which is especially powerful when it comes to analyzing data and generating reports. To put it simply, awk reads the file line-by-row, using spaces as the default delimiter to slice each row, and then perform various analytical processing of the cut.

There are 3 different versions of awk: awk, Nawk, and gawk, which are not specifically described, generally referred to as gawk, Gawk is the GNU version of AWK.

Awk has its name from the first letter of its founder Alfred Aho, Peter Weinberger and Brian Kernighan's surname. In fact, Awk does have its own language: The awk programming language, a three-bit creator has formally defined it as "style scanning and processing language." It allows you to create short programs that read input files, sort data, manipulate data, perform calculations on input, and generate reports, as well as countless other features.


How to use
awk ' {pattern + action} ' {filenames}

Although the operation can be complex, the syntax is always the same, where pattern represents what AWK looks for in the data, and the action is a series of commands that are executed when a match is found. Curly braces ({}) do not need to always appear in the program, but they are used to group a series of instructions according to a particular pattern. pattern is the regular expression to be represented, surrounded by slashes.


Example
#输出df第一个字段 [[email protected] ~]# df-ph |awk ' {print $} ' #输出df第一个和第三个字段 [[email protected] ~]# df-ph |awk ' {print $1,$3} ' # Output DF last field [[email protected] ~]# df-ph |awk ' {print $NF} ' #输出/var/log/messages to: Split the last field [[email protected] ~]# awk-f ': ' {print $NF} '/var/log/messages


This article from "Liang Childe" blog, please be sure to keep this source http://iyull.blog.51cto.com/4664834/1886353

Linux basic--awk text analysis tools

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.