How to use awk
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.
AWK Global variables specific methods are:
| The code is as follows |
Copy Code |
Cat Access.log |awk ' begin{devname= ';} ...' |
The ellipsis section is for awk processing code.
For example:
| code is as follows |
copy code |
| cat Tmp1.log | awk ' begin{start=0;tmp=0}{if ($ = = "Traceback") {Split ($0,b, "script ");p rint b[2];start=1;tmp=$11;} else {if (start ==1) {if ($11 = = tmp) {split ($0,b, "script ");p rint b[2];start=1;} else {start=0;print '}} ' |