awk command
# awk ' Condition 1{action 1} Condition 2{action 2} .... ' Filename
General use of relational expressions as criteria
Action: 1, formatted output 2, Flow control statement
column that handles the cut command cannot intercept spaces
Example: Intercepting disk usage
DF- H | grep "sda1" | awk ' Begin{print ' This was sda1 hard use persent: '} {print $} ' | Cut- F 1-d "%"
Begin keyword
A, before all actions are processed, you can add a script comment in the first line of the output text (as in the previous example)
b, custom intercept characters, use FS, must add begin, delete first row
FN Built-in variables
Custom Intercept characters
awk ' {fs= ': "}{print" \ T "$ /etc/passwd } '
Need to be modified to
awk ' begin{fs= ': "}{print" \ T "$ /etc/passwd "
End keyword
Command finishes, add end comment at end of output text
awk ' End{print ' This is END test!! '} {fs= ":"} {print $ \ t ' $ /etc/passwd } '
Relational operators
Displays disks with a disk share of more than 5%
DF- H | awk ' $5>5{print ' \ t ' $ ' | Cut- F 1-d "%"
Shell character intercept command awk