Summary of common awk Information

Source: Internet
Author: User


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 www.2cto.com + with any of the following 0 or multiple characters in A, B, or C: matching? 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 x www.2cto.com 3. test allowed by awk: Operator meaning x = y x Equal to 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 = gawk V variable meaning default value: Limit n argc command line parameter count g argind argv flag of the currently processed file n argv command line parameter array g convfmt number 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 record number www.2cto.com a fs input field separator space G IGNORECASE control case sensitivity 0 (Case sensitivity) A nf number of fields in the current record a nr number of records read 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 string matching the regular expression reg. Position N printf (format, variable) format output, output 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) www.2 of the uppercase character A atan (x, y) x in string. Cto.com N cos (x) x cosine (radian) A exp (x) e x power A int (x) x integer part A log (x) the natural logarithm of x to the sine (radian) A sqrt (x) x of the random number N sin (x) x between N rand () 0-1 A srand (x) initialize the random number generator. If x is ignored, system () G system () is used to return the time (in seconds) elapsed since January 1, January 1, 1970 by the author fengyv.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.