Fortune Telling Collection - Comprehensive fortune-telling - What is the explanation of the awk command?

What is the explanation of the awk command?

Simply put, awk is to read the file line by line, slice each line with spaces as the default separator, and then analyze the sliced part.

Awk is a powerful text analysis tool. Compared with searching grep and editing sed, it is especially powerful in analyzing data and generating reports.

Operation and judgment:

As one of the characteristics of a programming language, awk supports a variety of operations, which are basically the same as those provided by C language:+,-,*,/,% and so on. At the same time, awk also supports functions like++,-,+=,-=, =-in C language, which brings convenience for users who are familiar with C language to write awk programs.

As an extension of the operation function, awk also provides a series of built-in operation functions (such as log, sqr, cos, sin, etc. ) and some functions (such as length, substr, etc. ) is used to manipulate strings. The reference of these functions greatly improves the operation function of awk.

As a part of conditional branch instruction, relational judgment is the function of every programming language, and awk is no exception. Awk allows a variety of tests, such as the commonly used = = (equal to),! = (not equal to), > (greater than), > = (greater than or equal to), < = (less than or equal to) and so on. At the same time, as a style collocation, it also provides ~ (matching in) and! ~ (non-conformity) judgment.

As an extension of the test, awk also supports the use of logical operators:! (No),&; & amp; (AND), || (or) and brackets () make multiple judgments, which greatly enhances the function of awk. The appendix of this article lists the operations, judgments and operator priorities allowed by awk.