Split usage echohello_xiao_lan | running awk {max ($ 2max? $2: max)} END {printmax} test. t
Split usage echo hello_xiao_lan | awk '{split ($0, B, _); print B [3]}' // substr usage awk '{a = substr ($1, 2 ); print a} 'file2 // calculate the average awk '{sum = $ 1sum; count} END {print count, sum, sum/count} 'aa.txt awk' {max = ($ 2max? $2: max)} END {print max} 'test. t
Split usage
Echo "hello_xiao_lan" | awk '{split ($0, B, "_"); print B [3]}'
// Substr usage
Awk '{a = substr ($1, 2); print a}' file2
// Calculate the mean value
Awk '{sum = $1 + sum; count ++} END {print count, sum, sum/count}' aa.txt
Awk '{max = ($2> max? $2: max)} END {print max} 'test.txt
Group to maximize
Awk-F', ''{max [$1] = $2> max [$1]? $2: max [$1]} END {for (I in max) print I, max [I]} 't.txt
Group summation
Awk-F', ''{sum [$1] = sum [$1] + $2} END {for (I in sum) print I, sum [I]} 't.txt
// Input variable
Awk '{if ($1 = "' $ a'") print $0} 'test.txt
Sub usage:
Awk-F/'{sub (/[a-z] +. /, "", $3); print $3} 'I .txt // Replace the continuous string with null. (on the first match) changed to gsub, all of which were replaced.
// Number of rows containing a certain character
Awk 'in in {count = 0} {if ($0 ~ /Hello/) count ++} END {print count} 'test.txt
// Match and print again.
Awk-F "|" '{if ($3 ~ /Cc/) print $0} 'aa.txt
Awk-F "|" '$3 ~ /Cc/{print $0} 'aa.txt
// Next usage. If you call next, the commands after next will not be executed.
Awk '{if (NR = 1) {next} print $1, $2}' data // the data in the first row is not displayed
Awk-F "" '$1 = "I0012" {next} {print $0}' file2
// Getline usage, different from next. When getline is called, the following command is executed and the next row of data is used.
Awk-F "" '$1 = "I0012" {getline; print $0}' file2
Else usage
Awk-F' | ''{if ($1> 100) {print $1;} else {print" OK "} 'test1.txt
Strftime usage
Awk-F', ''{if ($2 =" 98B8E35530AB ") print $2, $3, $4, strftime ("% Y-% m-% d % T", $5)} 'test. log | head-3
// Print the current row number and the last column
Echo "1234/1234/bb234xx/134" | awk-F/'{print NR, $ NF }'
// Specify multiple separators
Awk-F' [:/t] ''{print $1, $3} 'test
// A row not starting with hello
Awk '! /^ Hello/'test.txt
// While usage
Echo "1234/1234/bb234xx/134" | awk-F'/''{I = 1; while (I
// For usage
Echo "1234/1234/bb234xx/134" | awk-F'/''{for (I = 1; I