1. regular Expression of awk metacharacters \ code sequences ^ start matching at the beginning of the string $ start matching at the end of the string. match any single string match any character in [ABC] and any character in [] Match [A-ca-C] match the characters in the A-C and a-c range (in alphabetical order) [^ ABC] matches any character other than [] with desk | chair matches any one of desk and chair with [ABC] [DEF. Matches any character in A, B, and C, and must be followed by any character in D, E, and F. * Matches any character in A, B, or C that appears 0 or multiple times + matches any one of A, B, or C that appears 1 or multiple times? Matches a null string or A, B, or C in any one character (Blue | black) Berry combines regular expressions to match blueberry or BlackBerry 2. usage of awk Arithmetic Operators ---------------- Y Power X of x ^ y x ** y same as X % Y to calculate the remainder of x/y (Modulo) X + Y x plus Yx-Y x minus Yx * Y x multiplied by Yx/Y x except y-y Minus Y (switch symbol of Y ); it is also called a one-time subtraction ++ y plus 1 and then use y (pre-added) y ++ with the Y value plus 1 (suffix added) -- Y minus 1 and use y (minus) y -- use Y minus 1 (minus suffix) X = Y: Assign the value of Y to xx + = Y. Assign the value of X + Y to XX-= Y. Then, assign the value of X-y to XX * = y and then x * the value of Y is assigned to XX/= Y. The value of x/y is assigned to x % = Y. The value of X % Y is assigned to XX ^ = Y. The value of x ^ y is assign XX ** = y the value of X ** Y to the test allowed by x3.awk: operator meaning x = Y x equals Yx! = Y x is not equal to Yx> Y x is greater than Yx> = Y x is greater than or equal to Yx <Y x is less than Yx <= Y x is less than or equal to Y? X ~ Re x matches the regular expression re? X !~ Re X does not match the regular expression re? 4. awk operators (sorted in ascending order of priority) =, + =,-=, * =,/=, % = ||&>>=<<==! = ~ !~ XY (string link, 'x' y' to "XY") +-*/% + + -- 5. awk built-in variables (pre-defined variables) Description: item V in the table indicates the first tool that supports variables (the same below): A = awk, n = nawk, P = POSIX awk, G = gawkv variable meaning default value 'n' argc command line parameter count g argind argv flag of the currently processed file n argv command line parameter array g convfmt digital conversion format %. 6gp environ Unix environment variable n errno UNIX system error message g fieldwidths input field width blank separator string a filename current input file name p fnr current number of records a FS input field separator space g ignorecase control case sensitivity 0 (Case sensitivity) a nf number of fields in the current record Number of records read by Nr A ofmt number output format %. 6ga OFS output field separator space a ors output record separator New Line A Rs input record other delimiter new line N rstart matched function matched string first n rlength matched function matched String Length N subsep subscript separator "\ 034" 6. awk built-in function V function usage or return value ------------------------------------------------ n gsub (Reg, String, target) replace stringn index (search, string) in target when the regular expression Reg matches) returns the position a length (string) of the search string in the string to evaluate the number of characters in the string. N match (string, Reg) returns the position n printf (Format, Variable) format the output, and output the variable in the format provided by format. N split (string, store, delim) breaks down string into the store array element N sprintf (format, variable) according to the delim, and returns a formatted data containing the format, variables is the data g strftime (format, timestamp) to be put in the string to return a format-based date or time string. timestmp is the time n sub (Reg, string, target) for the first time when the regular expression Reg matches, replace the string a substr (string, position, Len) in the target string to return a substring P totower (string) whose position starts with Len) returns the lowercase P toupper (string) character in string. returns the cotangent (radian) n cos (X) the cosine (radians) of x a exp (x) e x power a int (x) x integer part a log (x) x natural logarithm of N rand () the random number between 0 and 1. The square root of n sin (x) X is a srand (x), which is the sine (radian) a sqrt (x) X. If X is ignored, system () g system () is used to return the time elapsed since January 1, January 1, 1970 (in seconds)