awk Profiling file
1, the default per line by Space or tab segmentation, output text of 1, 4 awk ' {print $1,$4} ' Log.txt
2, specify split character ' comma ', output text of 1, 4 items awk-f, ' {print $1,$4} ' Log.txt
3, Set Variable awk-va=1 ' {print $1,$1+a} ' Log.txt; Awk-va=1-vb=s ' {print $1,$1+a,$1b} ' Log.txt
4, Operation,
| operator |
Description |
| = = = = *=/=%= ^= **= |
assignment |
| ?: |
C conditional expression |
| | | |
Logical OR |
| && |
logic and |
| ~ ~! |
matches regular expressions and mismatched regular expressions |
| < <= > >=!= = = |
relational operator filters The rows of the first column greater than 2 awk ' $1>2 ' Log.txt; filter the first column greater than 2 and Two columns equals ' Are ' line awk ' $1>2 && $2== ' Are ' {print $1,$2,$3} ' log.txt |
| space |
Connection |
| +- |
Plus, minus |
| */ |
multiply, except with remainder |
| +-! |
unary Plus, minus and logical non |
| ^ * * * |
exponentiation |
| + +-- |
increase or decrease, as a prefix or suffix |
| $ |
field reference |
| in |
array members |
5, built-in variables
| variable |
Description |
| \ $n |
Nth field in the current record, separated by FS |
| \$0 |
Full input record |
| ARGC |
Number of command line arguments |
| Argind |
The location of the current file on the command line (starting at 0) |
| Argv |
An array that contains command line arguments |
| Convfmt |
numeric conversion format (default value is%.6g) Environ environment variable associative array |
| Errno |
Description of the last system error |
| FieldWidths |
Field width list (separated by space key) |
| FILENAME |
Current file name |
| FNR |
with NR, but relative to the current file |
| Fs |
Field separator (default is any space) |
| IGNORECASE |
If true, a match that ignores the case |
| Nf |
Number of fields in current record
awk ' {print nf,$1,$2,$3} ' Log.txt |
| Nr |
Current number of records |
| Ofmt |
The output format of the number (the default value is%.6g) |
| OFS |
Output field separator (default is a space) |
| ORS |
Output record delimiter (default is a newline character) |
| Rlength |
The length of the string matched by the match function |
| Rs |
Record delimiter (default is a newline character) |
| Rstart |
The first position of the string that is matched by the match function |
| Subsep |
Array subscript Separator (default is/034) |
6, using regular expressions
The output contains the line of "re", awk '/re/' log.txt ~ expression mode begins. Medium is the pattern
The output second column contains "th" and prints the second column and the fourth column awk ' $ ~/th/{print $2,$4} ' Log.txt
Ignore case awk ' begin{ignorecase=1}/this/' Log.txt
Sed ' s/hi/hi/' replaces hi for hi
Sort File.txt | UNIQ-C statistics the number of times each row appears in a file
-N is sorted by number size,-r is in reverse order, K is the field that specifies the sort of love that needs to be sorted,-t specifies that the field delimiter is a colon
Zgrep run time: test.log.gz
|awk ' {print $ (NF-3), $ (NF-1)} '
|sed ' s/qt-[0-9]\{10,20\}//'
|sed ' s/pool-[0 -9]\{1,3\}-thread-[0-9]\{1,3\}//'
|sort
|uniq-c
|sed ' s/time://'
|sort-k 3n
|sed ' s/:method://'
|awk ' {if ($NF <=5) {a[$2 "5"] = = $} else if ($NF <=10) {a[$2 "10"] = = &NBSP
else if ($NF <=20) {a[$2 '] = = $} else if ($NF <=30) {a[$2 "30"] = =
Else if ($NF <=40) {a[$2] = = $} else if ($NF <=50) {a[$2 "50"] = = $}
Else if ($NF <=60) {a[$2] = = $} else {a[$2 "61+"] = {}} cs[$2] = $}
end{for (i in a)
{print I, a[i],a[i]/cs[substr (I,0,index (i, "")-1)]} '
|sort-k 1,1r-n-K 2
|awk ' {print ' \ t ' $ \ t ' $ ' \ t ' $} ' >~/all-htime2.txt