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