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)