Awk command usage, awk
Awk Programming Language/Data Processing Engine
Creator: Aho weinberger kernighan
Check input based on pattern matching (read row-by-row output)
Print the expected matching result to the screen
Syntax format:
Awk 'mode {operation}' file 1 file 2 .....
Common built-in Variables
The ordinal number of the row being processed by NR (row number)
FS fields are separated. The default value is space or Tab space.
$ N the nth field of the current row
$0 all text content of the current row
Output text by line number
Awk 'nr = 1, NR = 3 {print} 'file.txt
Awk '(NR = 1) | (NR = 3) {print}' file.txt
Use comparison operations
Awk '(NR % 2 = 1) {print}' file.txt outputs all odd rows
Awk '(NR % 2 = 0) {print}' file.txt outputs all even rows
Use Regular Expressions
Awk '/2/{print}' file.txt
Awk '/base $/{print}' file.txt
Specify the separator and specify the output Fields
Awk 'nr = 2, NR = 3 {print $1, $3} 'file.txt outputs the 1, 3 Field of Row 2-3
Awk-F. '$5 = "yes" {print $0}' file.txt output the fifth field separated by. Contains the rows of yes