• awk is a pattern-maching file processor
  • gawk is GNU version of awk

Arithmetic expresions:

  • binary operators: + – * / %
  • space between strings = concatenation
  • auto increment/ decrement: x++, ++x, x–, –x
  • assignment operators: +=, -=, *=, /=, %=
  • relational operators: ==, !=, >, >=, <, <=
  • regular expression: ~, !~
  • and, or, not: &&, ||, !

Built-in variables (awk):

  • ARGC = number of arguments in command line
  • ARGV = array of arguments – index starts from 0
  • FILENAME = current file name
  • FS = field separator (default = space)
  • NF = number of fields in current record
  • NR = ordinar number of the current record
  • OFMT = output format for numbers (default = “%.6g”)
  • OFS = output field separator (default = space)
  • ORS = output record separator (default = newline)
  • RS = records separator (default = newline)
  • $0 = entire input record
  • $n = nth field in current record, fields separated by FS

 

useful awk functions and commands:

  • # = comment until end of the line
  • and = bitwise AND -> and(expr1, expr2)
  • break  = exit from loop
  • continue = begin next iteration of loop
  • delete = delete element from array
  • do … while
  • exit = exit from script
  • for
  • function
  • if … else … fi
  • int = truncates number to its integer part
  • length = length of argument
  • or = bitwise OR (see and)
  • print
  • printf
  • rand
  • return
  • substr
  • tolower
  • toupper
  • xor = bitwise XOR