awk

an awk-ward (or not really) language.

some notes in process.

resources

gawk user's guide

awk tutorial: tutorialspoint

some built-in variables

$0 represents the entire input record, and $n the nth field in the current record (starting to count from 1)

awk tutorial: built-in variables

some built-in functions

awk tutorial: built-in functions

miscellaneous functions

string functions

strings

the index of the first character is 1!

misc

Explicit Input with getline

The getline command is used in several different ways and should not be used by beginners.

(?)

gawk

gawk user's guide

bit-manipulation functions

note: to run in compatibility mode, without gnu extensions, use the -c or --traditional flag:

$ awk -c

other notes

record separation

records separated by empty lines can be extracted with:

RS = ""

without modifying FS, fields will be separated by any whitespace, including newlines.

gawk allows regexp in RS, traditional awk will only accept one character.

field separation

one can get one character at a time by setting (in gawk?) :

FS = ""

loop through the elements of an array

arr["a"] = 1
arr["b"] = 2

for(key in arr)
  print key ": " arr[key]

incoming links

apuntes

wiki

advent of code 2021

most recent update on: 12021-12-13

source file

compudanzas home

text, images, and code are shared with the peer production license