Brief 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.
How to use:
awk [option] ' Pattern1{action1}pattern2{action2}' {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.
Awk built-in three variables
NF: Indicates that all current fields $nf represents the last field
FS: Default to Space-character separators
What line Nr:awk read to
awk Basic Usage
1, regexp: Regular expression, the format is/regular expreesion/
Awk-f: ' $3>=500{printf $ "\ n" \ n "} '/etc/passwd
2. Expression: expressions, which meet the criteria only if they are not 0 or non-null characters, such as ~ to indicate a match (similar to grep lookup line match)
Awk-f: ' $7!~ ' bash$ ' {printf $7 ' \ n '} '/etc/passwd
3, Ranges: Specify the matching range, the format is PAT1,PAT2
Awk-f: ' $ = = 0,$7~ ' nologin$ ' {printf $ ' \ t ' $7 ' \ n '} '/etc/passwd
4, Begin/end: Special mode,
Awk-f: ' begin{printf "Username shell\n"}$3 = = 0,$7~ "nologin$" {printf $ \ t "$7" \ n "} '/etc/passwd
5. Empty mode: Indicates no matching option
This article is from "think one or two" blog, please be sure to keep this source http://250919938.blog.51cto.com/962010/1918868
Shell's awk