Awk:
awk Syntax: awk mode {action}
Patterns: Regular, relational expressions, patterns, begin,end,
Action: consists of commands, functions, and expressions.
Text Source file Scores.txt
How to execute awk:
1. Execute under command line
2. Execute awk script awk-f script name file name
3. Executable awk Script
Pattern Matching for awk:
1. Use regular mode to print out the line beginning with T, and take the first column only
2. Interval mode, that is, pattern one and the middle of the pattern two rows are matched to
3.BEGIN mode, operation before reading the file line (can put some file description, variables, etc. written in this mode)
4.END mode, operating at the end, contrary to begin
Write a script about begin and end:
Note A detail question:
In the script, the pattern is not quoted, and the operation requires {}, and {needs and patterns are in one row
There are multiple actions in a pattern, then a newline is written
Below the command line, a quotation mark is inside a pattern, and an operation. Two patterns separated by semicolons;
System built-in variables in awk
(Record most times = line)
$ A record currently being processed
$n the first few fields
NF the number of fields currently logged
NR has read a few records
Filenam file name
FS Field Delimiter
RS Record delimiter default: line break
Example: Source file Articles.txt
To re-set the delimiter:
Operators and expressions can also be supported in awk
Such as
BEGIN {
X=5/2
Print X
}
Conditional expression:
Syntax: expression?value1:value2
Relational operators
, <,==, ~,!~, et cetera.
8==8 {print} Executes the print operation if 8=8 is true
Example: ~ is the meaning of the match
The following is a list of records that match the first field (column) that starts with a K print
Linux awk Learning