1. Role
Extract information
2. Grammar
awk 'pattern {action}' filename
pattern is a regular expression
action is the action of this information
awk logic:
In units, line by line reading process, and is separated by spaces, to obtain elements of each treatment.
3. Example
1, the first column (field) of the print file: awk '{Print $ 1}' filename 2, the print file first two columns (fields): awk '{Print $ 1, $ 2}' filename . 3, the first row has been printed, then print the second column: awk '{print $ 1 $ 2}' filename total number of rows 4, print text files: awk 'Print the END {NR}' filename . 5, the first line of printed text: awk 'NR == 1 {print } 'filename . 6, the printed text of the second row, first column: sed -n "2, 1p" filename | awk' print $ 1 '
Awk variables used above, the following variables
Command line argument number ARGC ARGV command line parameters are arranged ENVIRON supports the system environment variables queue FILENAME awk browse the file name record number of the file browsing FNR FS setting input field separator, which is equivalent to the command line option -F NF History number of fields recording the number of read NR OFS output field separator ORS output record separator RS control record separator $ 0 refers to the entire record variable. $ 1 represents the first field of the current line, $ 2 represents the second field of the current line, ...... and so on. $ NF is the number finally, information indicating the last one, with the variable NF is different, variable NF is the total number of statistics for each of the ranks
Recommended blog: