Reorganize `awk` notes.
parent
33466a2583
commit
74e7b8df0c
|
@ -108,10 +108,10 @@
|
|||
"algorithms/index.md": "f63290ca8d7aad1840797ec699188e9e",
|
||||
"algorithms/sorting/index.md": "2d5a18a3079d96fa9e3d4289181a8b6c",
|
||||
"algorithms/sorting/insertion-sort.md": "bdac9a5836611d6136b65367bed521e7",
|
||||
"bash/index.md": "3e4738d8d3531bb7a5afc53a2d73036c",
|
||||
"bash/index.md": "22083ea1ee9505cc96b02f82f63ba2c9",
|
||||
"bash/prompts.md": "61cb877e68da040a15b85af76b1f68ba",
|
||||
"bash/quoting.md": "b1d8869a91001f8b22f0cdc54d806f61",
|
||||
"bash/robustness.md": "7ab094b95ba2bfa885adba8e9efedf68",
|
||||
"bash/robustness.md": "6f3e4ec7c321b2f3f94a01c18f675d1e",
|
||||
"bash/shebang.md": "9006547710f9a079a3666169fbeda7aa",
|
||||
"c/escape-sequences.md": "7b4bbf159908320249158acfe47a9074",
|
||||
"c/index.md": "a021c92f19831bdd2bca4cbf813882fe",
|
||||
|
@ -148,7 +148,7 @@
|
|||
"algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65",
|
||||
"algorithms/order-growth.md": "53d41d9abbd1d8118793bad3996d249a",
|
||||
"_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac",
|
||||
"algorithms/sorting/selection-sort.md": "997feca70660168b3a115df6b5d5672e",
|
||||
"algorithms/sorting/selection-sort.md": "5ba56adddaf07653290af88f998f6c4a",
|
||||
"algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97",
|
||||
"binary/hexadecimal.md": "c3d485f1fd869fe600334ecbef7d5d70",
|
||||
"binary/index.md": "9089c6f0e86a0727cd03984f51350de0",
|
||||
|
@ -202,8 +202,8 @@
|
|||
"combinatorics/additive-principle.md": "e968028670f95ee9a7c5499ff7cb6792",
|
||||
"_journal/2024-02-19.md": "30d16c5373deb9cb128d2e7934ae256a",
|
||||
"_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
|
||||
"combinatorics/permutations.md": "05744081be9ae2962cf5ba817b5357d2",
|
||||
"combinatorics/combinations.md": "5ae0152180a1af7187c43606a4002202",
|
||||
"combinatorics/permutations.md": "19fd719c756040b31b7aea9595d9fb54",
|
||||
"combinatorics/combinations.md": "a6a05717313bfcde5365691bca7c35d3",
|
||||
"_journal/2024-02-20.md": "b85ba0eeeb16e30a602ccefabcc9763e",
|
||||
"_journal/2024-02/2024-02-19.md": "df1a9ab7ab89244021b3003c84640c78",
|
||||
"combinatorics/inclusion-exclusion.md": "202a60120d451676d44df4d0be30a45a",
|
||||
|
@ -214,7 +214,7 @@
|
|||
"_journal/2024-02/2024-02-21.md": "f423137ae550eb958378750d1f5e98c7",
|
||||
"_journal/2024-02-23.md": "219ce9ad15a8733edd476c97628b71fd",
|
||||
"_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b",
|
||||
"c17/strings.md": "3335356dee2b0e28a356adc851ee1375",
|
||||
"c17/strings.md": "55456a1d5b854d5d4f87184f03461db9",
|
||||
"c17/index.md": "78576ee41d0185df82c59999142f4edb",
|
||||
"c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500",
|
||||
"c17/declarations.md": "cec6866dff8ad160467df62cfceb6872",
|
||||
|
@ -233,7 +233,7 @@
|
|||
"filesystems/cas.md": "34906013a2a60fe5ee0e31809b4838aa",
|
||||
"git/objects.md": "e9b98576291ca04496c2f0863f526cfa",
|
||||
"git/index.md": "83d2d95fc549d9e8436946c7bd058d15",
|
||||
"encoding/integer.md": "14cbb409fde144875d75eefc53ce7f35",
|
||||
"encoding/integer.md": "6b9e0589706f57089a1c2ede93dc43b8",
|
||||
"_journal/2024-02-29.md": "f610f3caed659c1de3eed5f226cab508",
|
||||
"_journal/2024-02/2024-02-28.md": "7489377c014a2ff3c535d581961b5b82",
|
||||
"_journal/2024-03-01.md": "a532486279190b0c12954966cbf8c3fe",
|
||||
|
@ -278,12 +278,22 @@
|
|||
"_journal/2024-03/2024-03-15.md": "e54b2513beac5f46313b4c37622adf39",
|
||||
"_journal/2024-03-17.md": "72e99c7630085aee2c7f340a06b5ada7",
|
||||
"_journal/2024-03/2024-03-16.md": "ab7629c24ebe70838072cf6acec47cb0",
|
||||
"encoding/floating-point.md": "6aa91498473ea5f8504dfa7f87bf77f4",
|
||||
"encoding/floating-point.md": "376c963b043e4f4f603b2eaa3cfdb8ae",
|
||||
"_journal/2024-03-18.md": "8479f07f63136a4e16c9cd07dbf2f27f",
|
||||
"_journal/2024-03/2024-03-17.md": "23f9672f5c93a6de52099b1b86834e8b",
|
||||
"set/directed-graph.md": "b4b8ad1be634a0a808af125fe8577a53",
|
||||
"set/index.md": "b82a215fbee3c576186fc1af93c82fcb",
|
||||
"set/graphs.md": "938b5313e97eb364c97d752fdb262a52"
|
||||
"set/graphs.md": "dda79b615896d19a3041fbc0ee16b1da",
|
||||
"_journal/2024-03-19.md": "a0807691819725bf44c0262405e97cbb",
|
||||
"_journal/2024-03/2024-03-18.md": "63c3c843fc6cfc2cd289ac8b7b108391",
|
||||
"awk/variables.md": "e40a20545358228319f789243d8b9f77",
|
||||
"awk/regexp.md": "4ce38103575a5321a1503b28e1d714dd",
|
||||
"awk/index.md": "257738d2d864933fb4bd21e8609c525d",
|
||||
"_journal/2024-03-20.md": "2e81bab565b347d045ffee4123009bbf",
|
||||
"_journal/2024-03/2024-03-19.md": "a24995a82bcebcc2b2aa5815a19a8af7",
|
||||
"posix/awk/variables.md": "cc7e912c7fbda552d27e2064d84d15a5",
|
||||
"posix/awk/regexp.md": "46ceac3d5225ea3f3a375d74c2e2e0e9",
|
||||
"posix/awk/index.md": "cac4a1db94f9fc39c5e63ff6994b76aa"
|
||||
},
|
||||
"fields_dict": {
|
||||
"Basic": [
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: "2024-03-20"
|
||||
---
|
||||
|
||||
- [x] Anki Flashcards
|
||||
- [x] KoL
|
||||
- [ ] Sheet Music (10 min.)
|
||||
- [ ] Go (1 Life & Death Problem)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
- [ ] Interview Prep (1 Practice Problem)
|
||||
- [ ] Log Work Hours (Max 3 hours)
|
||||
|
||||
* Purged some Anki flashcards with tags: `lua`, `cncf`. In general, want to avoid on this next pass including any sort of flashcards around languages outside of C and:
|
||||
* `awk`
|
||||
* Bash
|
||||
* Lean
|
||||
* Assembly
|
||||
* Made distinctions in flashcards between POSIX `awk` features and GNU `awk` features. Only a few exceptions that may have been misleading so far (GNU's implementation allowing `FS` to be null and `RS` to be a regexp).
|
|
@ -12,4 +12,5 @@ title: "2024-03-18"
|
|||
|
||||
* Finished [buffer pool manager project](https://15445.courses.cs.cmu.edu/fall2022/project1/).
|
||||
* Added notes on [[graphs|graph]]-related terminology. Updated "Introduction to Algorithms" to fourth edition.
|
||||
* Watched [How My Student Became 1 Dan](https://www.youtube.com/watch?v=ZvHL_lwfYYI&t=595s).
|
||||
* Watched [How My Student Became 1 Dan](https://www.youtube.com/watch?v=ZvHL_lwfYYI&t=595s).
|
||||
* Reviewed and commented on Gus's latest pass of soft skills course.
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: "2024-03-19"
|
||||
---
|
||||
|
||||
- [x] Anki Flashcards
|
||||
- [x] KoL
|
||||
- [ ] Sheet Music (10 min.)
|
||||
- [ ] Go (1 Life & Death Problem)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
- [ ] Interview Prep (1 Practice Problem)
|
||||
- [x] Log Work Hours (Max 3 hours)
|
||||
|
||||
* Read sections 3.1 through 3.3 of "Computer Systems: A Programmer's Perspective". Skimmed the rest of the chapter.
|
||||
* Piggybacking off of this, read some historical context on different processor developers. Though I'd like to learn a bit more about the different processors and architectures, I'll limit my focus to the x86 processor line for the time-being.
|
|
@ -56,7 +56,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Is `SELECTION_SORT` in place?
|
||||
Back: Yes
|
||||
Back: Yes.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1707398773328-->
|
||||
END%%
|
||||
|
@ -64,7 +64,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Is `SELECTION_SORT` stable?
|
||||
Back: No
|
||||
Back: No.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1707398773330-->
|
||||
END%%
|
||||
|
@ -72,7 +72,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Is `SELECTION_SORT` adaptive?
|
||||
Back: No
|
||||
Back: No.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1707504634778-->
|
||||
END%%
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
---
|
||||
title: Bash
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: bash
|
||||
tags:
|
||||
- bash
|
||||
---
|
||||
|
|
|
@ -9,7 +9,7 @@ tags:
|
|||
|
||||
## Overview
|
||||
|
||||
An interesting point Robbins discusses in his introduction to [[gawk/index|gawk]] is this idea of command robustness. He states that:
|
||||
An interesting point Robbins discusses in his introduction to [[posix/awk/index|gawk]] is this idea of command robustness. He states that:
|
||||
|
||||
> A self-contained shell script is more reliable because there are no other files to misplace.
|
||||
|
||||
|
@ -59,7 +59,7 @@ It's interesting to think what else can be used as a measure of a command's robu
|
|||
* The presence of timeouts
|
||||
* Perhaps a program waits a specified amount of time before input is available. The command's success is now externally determined.
|
||||
* Locale-aware functionality
|
||||
* Consider for instance [[gawk/index|gawk]]'s `\u` [[escape-sequences|sequence]] which targets characters in the current locale's character set as opposed to specifically Unicode.
|
||||
* Consider for instance [[posix/awk/index|gawk]]'s `\u` [[escape-sequences|sequence]] which targets characters in the current locale's character set as opposed to specifically Unicode.
|
||||
* POSIX standard [[posix/regexp#Character Classes|character classes]] serve as another example.
|
||||
|
||||
The above scenarios are what makes something like [[nix/index|nix]] so compelling.
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
---
|
||||
title: Escape Sequences
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: c17
|
||||
tags:
|
||||
- c17
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
C has a standard for processing different escape sequences. Many languages built with C in mind parse these escape sequences in a similar way.
|
||||
|
||||
* `\ooo`: Consists of one to three octal digits.
|
||||
* [[bash/index|Bash]] supports this sequence as `$'\ooo'`.
|
||||
* [[gawk/index|gawk]] supports this sequence directly.
|
||||
* [[lua/index|Lua]] does not support this kind of escape sequence. Instead, it has a *decimal* escape sequence `\ddd`.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How are C escape sequences for octal digits denoted?
|
||||
Back: As `\ooo`.
|
||||
Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
<!--ID: 1706975891805-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In C, `\ooo` allows specifying how many octal digits?
|
||||
Back: One to three.
|
||||
Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
<!--ID: 1706975891810-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How are C escape sequences exposed in bash?
|
||||
Back: Using ANSI-C quoting, i.e. `$$'string'`.
|
||||
Reference: Mendel Cooper, “Advanced Bash-Scripting Guide,” n.d., 916.
|
||||
Tags: bash
|
||||
<!--ID: 1706975891817-->
|
||||
END%%
|
||||
|
||||
* `\xhh`: Consists of one or more [[radices#Hexadecimal|hexadecimal]] digits. The `x` prefix is required to distinguish from octal escape sequences.
|
||||
* [[bash/index|Bash]] supports this sequence as `$'\xhh'`. One or two digits is supported.
|
||||
* [[gawk/index|gawk]] limits processing to two digits.
|
||||
* Robbins states that using more than two hexadecimal digits can produce undefined results.
|
||||
* [[Lua/index|Lua]] requires *exactly* two digits in its hex escape sequence.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How are C escape sequences for hexadecimal digits denoted?
|
||||
Back: As `\xhh`.
|
||||
Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
<!--ID: 1706975891820-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In C, `\x` allows specifying how many hexadecimal digits?
|
||||
Back: One or more.
|
||||
Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
<!--ID: 1706975891824-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What footgun does C's `\x` sequence expose?
|
||||
Back: Using more than two hexadecimal digits can produce undefined results.
|
||||
Reference: Arnold D. Robbins, “GAWK: Effective AWK Programming,” October 2023, [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf).
|
||||
<!--ID: 1706975891828-->
|
||||
END%%
|
||||
|
||||
* `\uhhhh`: Introduced in C11 to represent Unicode code points. *Must* have exactly four hexadecimal characters specified with `0` leading padding if necessary.
|
||||
* [[bash/index|Bash]] supports this sequence as `$'uhhhh'`. One to four hex digits is supported.
|
||||
* [[gawk/index|gawk]] consolidates C's `\u` and `\U` sequence marker into just `\u`, capable of handling one to eight digits. Furthermore, `gawk` uses `\u` to designate the current locale's character set, *not* Unicode directly. Often times this is some Unicode-based locale though.
|
||||
* [[lua/index|Lua]] consolidates C's `\u` and `\U` sequence markers into `\u{h...h}`, capable of handling one or more hexadecimal digits. The curly braces are required.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two ways are C escape sequences for unicode denoted?
|
||||
Back: As `\uhhhh` or `\Uhhhhhhhh`.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706975891832-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In C, `\u` allows specifying how many hexadecimal digits?
|
||||
Back: Exactly four.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706975891835-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In what standard were C's `\u` and `\U` escape sequences introduced?
|
||||
Back: C11.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706975891839-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
`\u` in C designates a character in {Unicode}. In `gawk` it designates a character in {the current locale's character set}.
|
||||
Reference: Arnold D. Robbins, “GAWK: Effective AWK Programming,” October 2023, [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf).
|
||||
Tags: unicode gawk
|
||||
<!--ID: 1706976541399-->
|
||||
END%%
|
||||
|
||||
* `\Uhhhhhhhh`: Introduced in C11 to represent larger unicode code points. *Must* have exactly eight hexadecimal characters specified with `0` leading padding if necessary.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In C, `\U` allows specifying how many hexadecimal digits?
|
||||
Back: Exactly eight.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706975891843-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Why does C have both `\u` and `\U`?
|
||||
Back: `\U` accommodates for larger code point values.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706976705750-->
|
||||
END%%
|
||||
|
||||
## References
|
||||
|
||||
* Arnold D. Robbins, “GAWK: Effective AWK Programming,” October 2023, [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf).
|
||||
* Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
* Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
* Mendel Cooper, “Advanced Bash-Scripting Guide,” n.d., 916.
|
||||
* Roberto Ierusalimschy, _Programming in Lua_, Fourth edition (Rio de Janeiro: Lua.org, 2016).
|
|
@ -730,11 +730,11 @@ Tags: printf
|
|||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Cloze
|
||||
The {`%G`} format specifier outputs a {uppercase `double` in fixed-point or standard notation}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1710599806324-->
|
||||
<!--ID: 1710844199536-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
|
@ -767,7 +767,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
How does `%g` handle non-integral values differently from `%f`?
|
||||
Back: It excludes insignifant `0`s after the `.`.
|
||||
Back: It excludes insignifant `0`s after the decimal point.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1710603411174-->
|
||||
|
@ -784,7 +784,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the output of `printf("%g", 3.14)`?
|
||||
Assuming fixed-point notation, what is the output of `printf("%g", 3.14)`?
|
||||
Back: `3.14`
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
|
@ -793,7 +793,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the output of `printf("%g", 3)`?
|
||||
Assuming fixed-point notation, what is the output of `printf("%g", 3)`?
|
||||
Back: `3`
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
|
@ -948,7 +948,123 @@ Tags: printf
|
|||
<!--ID: 1708454584568-->
|
||||
END%%
|
||||
|
||||
## Escape Sequences
|
||||
|
||||
C has a standard for processing different escape sequences. Many languages built with C in mind parse these escape sequences in a similar way.
|
||||
|
||||
* `\ooo`: Consists of one to three octal digits.
|
||||
* [[bash/index|Bash]] supports this sequence as `$'\ooo'`.
|
||||
* [[posix/awk/index|awk]] supports this sequence directly.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How are C escape sequences for octal digits denoted?
|
||||
Back: As `\ooo`.
|
||||
Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
<!--ID: 1706975891805-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In C, `\ooo` allows specifying how many octal digits?
|
||||
Back: One to three.
|
||||
Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
<!--ID: 1706975891810-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How are C escape sequences exposed in bash?
|
||||
Back: Using ANSI-C quoting, i.e. `$$'string'`.
|
||||
Reference: Mendel Cooper, “Advanced Bash-Scripting Guide,” n.d., 916.
|
||||
Tags: bash
|
||||
<!--ID: 1706975891817-->
|
||||
END%%
|
||||
|
||||
* `\xhh`: Consists of one or more [[radices#Hexadecimal|hexadecimal]] digits. The `x` prefix is required to distinguish from octal escape sequences.
|
||||
* [[bash/index|Bash]] supports this sequence as `$'\xhh'`. One or two digits is supported.
|
||||
* POSIX [[posix/awk/index|awk]] does not support this sequence.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How are C escape sequences for hexadecimal digits denoted?
|
||||
Back: As `\xhh`.
|
||||
Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
<!--ID: 1706975891820-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In C, `\x` allows specifying how many hexadecimal digits?
|
||||
Back: One or more.
|
||||
Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
<!--ID: 1706975891824-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What footgun does C's `\x` sequence expose?
|
||||
Back: Using more than two hexadecimal digits can produce undefined results.
|
||||
Reference: Arnold D. Robbins, “GAWK: Effective AWK Programming,” October 2023, [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf).
|
||||
<!--ID: 1706975891828-->
|
||||
END%%
|
||||
|
||||
* `\uhhhh`: Introduced in C11 to represent Unicode code points. *Must* have exactly four hexadecimal characters specified with `0` leading padding if necessary.
|
||||
* [[bash/index|Bash]] supports this sequence as `$'uhhhh'`. One to four hex digits is supported.
|
||||
* POSIX [[posix/awk/index|awk]] does not support this sequence.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two ways are C escape sequences for unicode denoted?
|
||||
Back: As `\uhhhh` or `\Uhhhhhhhh`.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706975891832-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In C, `\u` allows specifying how many hexadecimal digits?
|
||||
Back: Exactly four.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706975891835-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In what standard were C's `\u` and `\U` escape sequences introduced?
|
||||
Back: C11.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706975891839-->
|
||||
END%%
|
||||
|
||||
* `\Uhhhhhhhh`: Introduced in C11 to represent larger unicode code points. *Must* have exactly eight hexadecimal characters specified with `0` leading padding if necessary.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In C, `\U` allows specifying how many hexadecimal digits?
|
||||
Back: Exactly eight.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706975891843-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Why does C have both `\u` and `\U`?
|
||||
Back: `\U` accommodates for larger code point values.
|
||||
Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
Tags: unicode
|
||||
<!--ID: 1706976705750-->
|
||||
END%%
|
||||
|
||||
## References
|
||||
|
||||
* Arnold D. Robbins, “GAWK: Effective AWK Programming,” October 2023, [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf).
|
||||
* Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language*, 2nd ed (Englewood Cliffs, N.J: Prentice Hall, 1988).
|
||||
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
* Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020).
|
||||
* Mendel Cooper, “Advanced Bash-Scripting Guide,” n.d., 916.
|
||||
* “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
|
|
|
@ -432,7 +432,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
What is the integer lattice?
|
||||
Back: $\{(x, y) : x \in \omega \land y \in \omega\}$
|
||||
Back: $\omega \times \omega = \{(x, y) : x \in \omega \land y \in \omega\}$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708384441429-->
|
||||
END%%
|
||||
|
|
|
@ -85,14 +85,6 @@ Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n
|
|||
<!--ID: 1708366788580-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What combinatorial concept is often associated with the factorial?
|
||||
Back: Permutations.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708366788583-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How does sorting relate to the concept of permutations?
|
||||
|
|
|
@ -867,7 +867,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the largest unsigned interpretation of a `float`'s exponent *field*?
|
||||
What is the largest unsigned decimal value a normalized `float`'s exponent field can be?
|
||||
Back: $2^8 - 2$
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
|
@ -885,7 +885,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the largest unsigned interpretation of a `double`'s exponent field?
|
||||
What is the largest unsigned decimal value a normalized `double`'s exponent field can be?
|
||||
Back: $2^{11} - 2$
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
|
@ -936,7 +936,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
How does the largest unsigned interpretation of the exponent *field* relate to the $Bias$?
|
||||
Back: The largest unsigned interpretation is $2 \times Bias$.
|
||||
Back: The largest unsigned interpretation is $2 \cdot Bias$.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1710605798347-->
|
||||
END%%
|
||||
|
|
|
@ -30,7 +30,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
In what two ways are C integral types encoded?
|
||||
In what two ways are C integral types usually encoded?
|
||||
Back: Unsigned encoding or two's-complement.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
|
@ -838,7 +838,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
*Why* does sign extension of unsigned numbers generally not work?
|
||||
Back: It actually does, though we technically call it zero extension.
|
||||
Back: If new bits have value `1`, we're adding powers of $2$ to the interpreted value.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1708697867833-->
|
||||
END%%
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
title: GAWK
|
||||
title: AWK
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: linux::cli gawk
|
||||
FILE TAGS: linux::cli posix::awk
|
||||
tags:
|
||||
- gawk
|
||||
- awk
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
@ -308,12 +308,6 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202
|
|||
<!--ID: 1707618833562-->
|
||||
END%%
|
||||
|
||||
## Exit Status
|
||||
|
||||
On success, `gawk` exits with status code `EXIT_SUCCESS`. On failure, with status code `EXIT_FAILURE`. On fatal error, `gawk` exists with status code `2`. #c17
|
||||
|
||||
You can specify a custom exit status by using the `exit` statement from within the `awk` program.
|
||||
|
||||
## References
|
||||
|
||||
* Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
title: Regular Expressions
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: linux::cli gawk regexp
|
||||
FILE TAGS: linux::cli posix::awk regexp
|
||||
tags:
|
||||
- gawk
|
||||
- awk
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
@ -13,7 +13,7 @@ Most `awk` patterns are regular expressions delimited with `/`. We can use `~` a
|
|||
```bash
|
||||
# Matches any line with `li` somewhere.
|
||||
$ awk '/li/' data
|
||||
$ awk `$0 ~ /li/` data
|
||||
$ awk '$0 ~ /li/' data
|
||||
# Matches any line with `li` somewhere in the first field.
|
||||
$ awk '$1 ~ /li/' data
|
||||
```
|
||||
|
@ -31,6 +31,47 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202
|
|||
<!--ID: 1707231831794-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is the following equivalently written using `~`?
|
||||
```bash
|
||||
$ awk '/li/' data
|
||||
```
|
||||
Back:
|
||||
```bash
|
||||
$ awk '$0 ~ /li/' data
|
||||
```
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
<!--ID: 1710940567898-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What operator is used for regexp matching?
|
||||
Back: `~`
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
<!--ID: 1710940567902-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What operator is used for regexp non-matching?
|
||||
Back: `!~`
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
<!--ID: 1710940567906-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How do we write a pattern where the second field matches regexp `/li/`?
|
||||
Back:
|
||||
```bash
|
||||
$ awk '$2 ~ /li/' {...}
|
||||
```
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
<!--ID: 1710940567909-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
In `awk`, `/.../` is to a {regexp} constant whereas `"..."` is to a {string} constant.
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
title: Variables
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: linux::cli gawk
|
||||
FILE TAGS: linux::cli posix::awk
|
||||
tags:
|
||||
- gawk
|
||||
- awk
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
@ -80,7 +80,8 @@ END%%
|
|||
Cloze
|
||||
The {`RT`} variable matches the {input characters that matched `RS`}.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
<!--ID: 1707310981386-->
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1710938533567-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
|
@ -88,7 +89,16 @@ Basic
|
|||
Barring the final record, when is `RT` always equal to `RS`?
|
||||
Back: When `RS` is a string containing a single character.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
<!--ID: 1707310981388-->
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1710938533571-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Why is the gawk `RT` variable unnecessary in POSIX `awk`?
|
||||
Back: Because POSIX `awk` does not permit setting `RS` to a regexp.
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1710939301099-->
|
||||
END%%
|
||||
|
||||
* `RS` (**R**ecord **S**eparator)
|
||||
|
@ -100,7 +110,7 @@ END%%
|
|||
| `"\n"` | Records are separated by the newline character. This is the default. |
|
||||
| *any single character* | Records are separated by each occurrence of the character. Multiple successive occurrences delimit empty records. |
|
||||
| `""` | Records are separated by one or more blank lines. Leading/trailing newlines in a file are ignored. If `FS` is a single character, then `"\n"` also serves as a field separator. |
|
||||
| *regexp* | Records are separated by occurrences of characters that match *regexp*. Leading/trailing matches delimit empty records. |
|
||||
| *regexp* | Records are separated by occurrences of characters that match *regexp*. Leading/trailing matches delimit empty records. (**GNU only**) |
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
|
@ -117,10 +127,28 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202
|
|||
<!--ID: 1707310981380-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is `RS = "ab"` interpreted in POSIX `awk`?
|
||||
Back: As if we had instead written `RS = "a"`.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
<!--ID: 1710939301103-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is `RS = "ab"` interpreted in GNU `awk`?
|
||||
Back: As a regex matching strings `"ab"`.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1710939301107-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
If `RS` is a string with {more than one character}, it is treated as a {regexp}.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1707310981384-->
|
||||
END%%
|
||||
|
||||
|
@ -129,6 +157,7 @@ Basic
|
|||
What value of `RS` may `gawk` not process correctly?
|
||||
Back: A regexp with optional trailing part, e.g. `AB(XYZ)?`.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1707310981390-->
|
||||
END%%
|
||||
|
||||
|
@ -161,6 +190,7 @@ Basic
|
|||
What distinguishes `RS` value `""` and `\n\n+`?
|
||||
Back: When set to the former, `awk` strips leading/trailing newlines from the file.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1707829409170-->
|
||||
END%%
|
||||
|
||||
|
@ -240,13 +270,13 @@ END%%
|
|||
* `FS` (**F**ield **S**eparator)
|
||||
* The separator used to distinguish fields from one another.
|
||||
|
||||
`FS == ??` | Description
|
||||
---------------------------- | -------------------------------------
|
||||
`" "` | Fields are separated by runs of whitespace. Leading/trailing whitespace is ignored. This is the default.
|
||||
*any other single character* | Fields are separated by each occurrence of the character. Multiple successive occurrences delimit empty fields, as do leading/trailing occurrences.
|
||||
`"\n"` | Specific instance of the above row. It is used to treat the record as a single field (assuming newlines separate records).
|
||||
*regexp* | Fields are separated by occurrences of characters that match *regexp*. Leading/trailing matches delimit empty fields.
|
||||
`""` | Each individual character in the record becomes a separate field.
|
||||
| `FS == ??` | Description |
|
||||
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `" "` | Fields are separated by runs of whitespace. Leading/trailing whitespace is ignored. This is the default. |
|
||||
| *any other single character* | Fields are separated by each occurrence of the character. Multiple successive occurrences delimit empty fields, as do leading/trailing occurrences. |
|
||||
| `"\n"` | Specific instance of the above row. It is used to treat the record as a single field (assuming newlines separate records). |
|
||||
| *regexp* | Fields are separated by occurrences of characters that match *regexp*. Leading/trailing matches delimit empty fields. |
|
||||
| `""` | Each individual character in the record becomes a separate field. (**GNU only**) |
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
|
@ -297,9 +327,27 @@ END%%
|
|||
Cloze
|
||||
Setting `FS` to {`""`} allows examining {each character of a record separately}.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1707756447064-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is `FS = ""` interpreted in POSIX `awk`?
|
||||
Back: As a no-op.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
<!--ID: 1710939301112-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is `FS = ""` interpreted in GNU `awk`?
|
||||
Back: Each individual character in the record becomes a separate field.
|
||||
Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf)
|
||||
Tags: gnu::awk
|
||||
<!--ID: 1710939301117-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
If `RS` has its default value, setting `FS` to {`"\n"`} treats the {record as the single field}.
|
Loading…
Reference in New Issue