compudanzas

awk

an awk-ward (or not really) language.

some notes in process.

projects

g2e is an opinionated gempub to epub converter written in awk:

g2e

my solutions for advent of code 2021 have been written in awk.

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

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

this approach might yield the results in different order depending on the awk implementation.

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

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

incoming links