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 the matching content is found. Curly braces ({}) do not need to appear in the program at all times, but they are used to group a series of instructions according to a specific pattern. pattern is the regular expression to be represented, surrounded by slashes.
Example
Awk takes out the specified line, such as Line 20th
cat/etc/hosts | awk ' nr==20 '
Awk takes out rows with 3 columns
cat/etc/hosts | awk ' nf==3 '
Print out the specified column
cat/etc/hosts | awk ' {print $} '
Print out the last column, the length of the column is uneven, but also print the last column
cat/etc/hosts | awk ' {print $NF} '
To remove a random row of a file using a remainder method
Countline= ' Cat Swapfile | Wc-l '
awk "nr==$ ($RANDOM% $countline))" Swapfile