Awk is a powerful text analysis tool, with the search for grep and the editing of SED, which is especially powerful when it comes to analyzing data and generating reports. To put it simply, awk reads the file line-by-row, using spaces as the default delimiter to slice each row, and then perform various analytical processing of the cut.
The awk workflow is this: reads a record with a ' \ n ' line break, then divides the record by the specified domain delimiter, fills the field, and $ $ represents all fields, representing the first field, $n representing the nth field. The default Domain delimiter is the "blank key" or "[tab] key"
Example: #cat/etc/passwd |awk-f ': ' {print $} '
Awk is a programming language that is used to process text and data under Linux/unix. The data can come from standard input (stdin), one or more files, or the output of other commands. It supports advanced functions such as user-defined functions and dynamic regular expressions, and is a powerful programming tool under Linux/unix. It is used in the command line, but more is used as a script. Awk has many built-in features, such as arrays, functions, and so on, which are the same as the C language, and flexibility is the advantage of Awk's greatness. awk command format and option syntax form awk [options] ' script ' Var=value file (s) awk [options]-F scriptfile var=value file (s) Common command option-f fs & nbsp FS specifies an input delimiter, and FS can be a string or regular expression, such as-f:-V var=value assigns a user-defined variable, passes an external variable to awk-f scripfile reads the awk command from the script file-m[fr] val set intrinsic limits on the Val value, the-MF option limits the maximum number of blocks allocated to Val; the-MR option limits the maximum number of records. These two features are the extended functionality of the Bell Lab version of AWK and are not available in standard awk. awk mode and Operation Awk scripts are made up of patterns and operations. The pattern pattern can be any one of the following:/Regular expression/: An extension set using a wildcard character. Relational expressions: Operations using operators, which can be comparison tests of strings or numbers. Pattern-matching expressions: with operator ~ (match) and ~ ~ (mismatch). BEGIN statement block, pattern statement block, END statement block: See how AWK works operation consists of one or more commands, functions, expressions, separated by a newline or semicolon, and in curly braces, the main part is: variable or array assignment output command built-in function control flow statement awk script basic Structure awk ' begin{print "Start"} pattern{commands} end{print "END"} ' file an awk script typically consists of a BEGIN statement block, a universal statement block capable of using pattern matching, an END language Sentence Block 3 part, these three parts are optional. Either part can not be present in the script, the script is usually enclosed in quotation marks or double quotes, for example: awk ' begin{i=0} {i++} end{print i} ' filename awk ' begin{ I=0} {i++} end{print i} "filename awk works awk ' begin{commands} pattern{commands} end{commands} ' first step: Execute begin{ The statement in the commands} statement block; the second step is to read a line from a file or standard input (stdin) and execute the pattern{commands} statement block, which scans the file line by row, repeating the process from the first line to the last line until the file is fully read. Step three: Execute the end{commands} statement block when reading to the end of the input stream. The BEGIN statement block is executed before awk begins to read the rows from the input stream, an optional block of statements, such as variable initialization, the table top statement of the PrintOut table, which can usually be written in the BEGIN statement block. The end statement block is executed after awk reads all the rows from the input stream, such as the analysis results for all rows, such as a summary of information that is done in the end statement block, which is also an optional block of statements. The generic command in the pattern statement block is the most important part, and it is optional. If the pattern statement block is not provided, the default is {print}, which prints every row read to, and every row that awk reads executes the statement block. Example Echo-e "A line 1nA Line 2" | awk ' begin{print "Start"} {print} end{print "END"} ' start A line 1 A lines 2 END when using print without parameters, it prints the current row when the print parameter is comma When you are separating, a space is used as the delimiter for printing. In Awk's print statement block, double quotes are used as concatenation characters, for example: Echo | awk ' {var1= ' v1 '; var2= "v2"; var3= "V3"; print var1,var2,var3;} ' v1 v2 v3 double quote stitching using: Echo | awk ' {var1= ' v1 '; var2= ' v2 '; var3= ' v3 '; print var1 "=" var2 "=" VAR3;} ' v1=v2=v3 {} is similar to a loop body that iterates over each line in a file, typically variable initialization statements (such as: i= 0) and the statement that prints the header of the file into the BEGIN statement block, placing statements such as printed results in the end statement block.
from: Http://man.linuxde.net/awk
Linux awk Command