From 8f6ded78070bc3b2eeef5af4b3124afe112178cb Mon Sep 17 00:00:00 2001 From: sejo Date: Tue, 30 Nov 2021 21:16:39 -0600 Subject: [PATCH] awk notes --- src/advent_of_code_2021.gmo | 7 +++++ src/apuntes.gmo | 1 + src/awk.gmo | 62 +++++++++++++++++++++++++++++++++++++ src/now.gmo | 2 ++ src/wiki.gmo | 2 +- 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/advent_of_code_2021.gmo create mode 100644 src/awk.gmo diff --git a/src/advent_of_code_2021.gmo b/src/advent_of_code_2021.gmo new file mode 100644 index 0000000..368ef7e --- /dev/null +++ b/src/advent_of_code_2021.gmo @@ -0,0 +1,7 @@ +# advent of code 2021: awk + +my first time participating in advent of code! + +=> https://adventofcode.com/2021/ + +decided to use {awk} as a programming language in order to keep practicing and learning it :) diff --git a/src/apuntes.gmo b/src/apuntes.gmo index 655746d..fb68a43 100644 --- a/src/apuntes.gmo +++ b/src/apuntes.gmo @@ -14,6 +14,7 @@ recordatorios de procesos => ./imagemagick.gmi {imagemagick} => ./ed.gmi {ed} => ./postfix.gmi {postfix} +=> ./awk.gmi {awk} ## misc diff --git a/src/awk.gmo b/src/awk.gmo new file mode 100644 index 0000000..66e2d06 --- /dev/null +++ b/src/awk.gmo @@ -0,0 +1,62 @@ +# awk + +an awk-ward (or not really) language. + +some notes in process. + +# some built-in variables + +* FS: input field separator (by default, space) +* RS: record field separator (by default, newline) +* NF: number of fields in current record +* NR: number of current record +* FNR: number of current record relative to current file +* OFS: output field separator (by default, space) +* ORS: output record separator (by default, newline) +* RLENGTH: length of the string matched by match( ) + +$0 represents the entire input record, and $n the nth field in the current record + +=> https://www.tutorialspoint.com/awk/awk_built_in_variables.htm awk tutorial: built-in variables + +# some built-in functions + + +=> https://www.tutorialspoint.com/awk/awk_built_in_functions.htm awk tutorial: built-in functions +=> https://www.tutorialspoint.com/awk/awk_miscellaneous_functions.htm miscellaneous functions +=> https://www.tutorialspoint.com/awk/awk_string_functions.htm string functions + +## strings + +the index of the first character is 1! + +* index( string, sub) : index of sub as a substring of string +* length( string ) +* match( string, regex ) : index of the longest match of regex in string +* split( string, arr, regex ) : split string into array using regex as separato +* printf( format, expr-list) +* strtonum(string): useful to convert from hexadecimal (0x prefix) or octal (0 prefix) +* gsub( regex, sub, string): global substitution of regex with sub in string. if string is ommited, $0 is used +* sub(regex, sub, string): substitute regex with sub in string, once. if string is omitted, $0 is used +* substr(string, start, len): returns the substring from start index, with length len. if len is ommitted, it goes until the end of the string +* tolower( str ) +* toupper( str ) + +## misc + +* getline: read the next line +* next: stops the current processing and start over with next line +* system: execute the specified command and returns its exit status +* delete: delete an element from an array, or an array + +# other notes + +## loop through the elements of an array + +``` +arr["a"] = 1 +arr["b"] = 2 + +for(key in arr) + print key ": " arr[key] +``` diff --git a/src/now.gmo b/src/now.gmo index ea1cadf..0716580 100644 --- a/src/now.gmo +++ b/src/now.gmo @@ -6,6 +6,8 @@ developing the {qiudanz technique} in the context of a micro-residency in the sl see the {qiudanz devlog} for updates! +participating in {advent of code 2021} + finished teaching an {intro to uxn programming} online workshop via babycastles academy! practicing/learning skateboarding. diff --git a/src/wiki.gmo b/src/wiki.gmo index c73e1d6..3216603 100644 --- a/src/wiki.gmo +++ b/src/wiki.gmo @@ -25,6 +25,6 @@ it is heavily inspired by xxiivv and several sites in that webring the source files are written in a gemtext-like format, ready to be used in the {gemini} protocol, and to be easily convertible to html. -the site is built to its corresponding formats with a custom engine composed of a shell script, awk scripts, and a python script. +the site is built to its corresponding formats with a custom engine composed of a shell script, {awk} scripts, and a python script. => https://tildegit.org/sejo/compudanzas compudanzas site generator and source files