Add more gawk flashcards.
parent
533c24f42f
commit
b2578161c4
|
@ -60,14 +60,17 @@
|
|||
"Linux/Signals.md": "f58f1a36a9fe53928fdc3dc02fc4c3e3",
|
||||
"linux/index.md": "6e50c924ee9e09294fd3b907fbdeaf0f",
|
||||
"linux/signals.md": "e9ab74723981ebc232189c84d3b0da74",
|
||||
"templates/daily.md": "0f22c7ef0b0f35efada88d61c95e9815",
|
||||
"templates/daily.md": "7866014e730e85683155207a02e367d8",
|
||||
"daily/2024-01-31.md": "72e343cef8d56e169cac7b360a88fcf0",
|
||||
"posix/index.md": "f7b1ae55f8f5e8f50f89738b1aca9111",
|
||||
"posix/signals.md": "26161c6a79a0c413032c6c17e460412c",
|
||||
"gawk.md": "9bf70ef138a9a281b86400aee393cae7",
|
||||
"posix/signals.md": "2120ddd933fc0d57abb93c33f639afd8",
|
||||
"gawk.md": "c0cf6decdf02f5513e386525b02bdf58",
|
||||
"bash/index.md": "3b5296277f095acdf16655adcdf524af",
|
||||
"bash/shebang.md": "bc30f75bcddff59d6f907fae89c17283",
|
||||
"bash/robustness.md": "e474fd33469fc393bfde45cd7b9411ba"
|
||||
"bash/shebang.md": "ad178efeb4a05190b80b5df108c175c7",
|
||||
"bash/robustness.md": "de97cd77aae047b5eea27440b43c9c42",
|
||||
"journal/2024-02-01.md": "f4cc061bfc8e41ce15ae9a354c65ffe9",
|
||||
"journal/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970",
|
||||
"bash/quoting.md": "8086c0a576f30d77248faac16a4be79e"
|
||||
},
|
||||
"fields_dict": {
|
||||
"Basic": [
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
title: Quoting
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: bash
|
||||
tags:
|
||||
- bash
|
||||
---
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How do you escape a `'` within a single-quote string?
|
||||
Back: This is impossible.
|
||||
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: 1706816752230-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What does the null string refer to?
|
||||
Back: The empty string, i.e. `""`.
|
||||
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: 1706816752237-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
When does Bash remove null strings from a command?
|
||||
Back: When they occur as part of a non-null command-line argument.
|
||||
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: 1706816752241-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is wrong with the following command?
|
||||
```bash
|
||||
$ # -F specifies the field separator
|
||||
$ awk -F"" 'program' files
|
||||
```
|
||||
Back: Bash removes the null string before executing the command.
|
||||
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: 1706816764555-->
|
||||
END%%
|
||||
|
||||
## 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)
|
|
@ -7,7 +7,9 @@ tags:
|
|||
- shell
|
||||
---
|
||||
|
||||
An interesting point Robbins[^robbins] discusses in his introduction to [[gawk]] is this idea of command robustness. He states that:
|
||||
## Overview
|
||||
|
||||
An interesting point Robbins discusses in his introduction to [[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.
|
||||
|
||||
|
@ -27,7 +29,7 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202
|
|||
<!--ID: 1706726911475-->
|
||||
END%%
|
||||
|
||||
The point he is arguing is that the first command below is considered more robust than the second since the command is more loosely coupled to its environment:
|
||||
He argues that the first command below is more robust than the second since the command is more loosely coupled to its environment:
|
||||
|
||||
```bash
|
||||
$ awk 'program' input-file1 input-file2 ...
|
||||
|
@ -55,4 +57,6 @@ It's interesting to think what else can be used as a measure of a command's robu
|
|||
* Whether a program acts atomically
|
||||
* Is it possible intermediate files are left that affect subsequent runs?
|
||||
|
||||
[^robbins]: 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)
|
||||
## 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)
|
||||
|
|
|
@ -6,6 +6,8 @@ tags:
|
|||
- bash
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The shebang (also writting shabang or sha-bang) is a magic character at the start of a script indicating what command should be run when invoking the script directly. It always begins with ASCII characters `#!`.[^mendel]
|
||||
|
||||
%%ANKI
|
||||
|
@ -44,12 +46,13 @@ Some systems limit the length of interpreters to just 32 characters. A simple wo
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What workaround is used when shabang interpreter names are too long?
|
||||
What workaround is used when shebang interpreter names are too long?
|
||||
Back: Introduce a symbolic link.
|
||||
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: 1706726911470-->
|
||||
END%%
|
||||
|
||||
[^mendel]: Cooper, Mendel. “Advanced Bash-Scripting Guide,” n.d., 916.
|
||||
## References
|
||||
|
||||
[^robbins]: 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)
|
||||
* Cooper, Mendel. “Advanced Bash-Scripting Guide,” n.d., 916.
|
||||
* 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)
|
113
notes/gawk.md
113
notes/gawk.md
|
@ -8,7 +8,7 @@ tags:
|
|||
- gawk
|
||||
---
|
||||
|
||||
## Introduction
|
||||
## Overview
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
|
@ -25,7 +25,7 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202
|
|||
<!--ID: 1706726911439-->
|
||||
END%%
|
||||
|
||||
> Dark corners are basically fractal - no matter how much you illuminate, there's always a smaller but darker one.
|
||||
> Dark corners are basically fractal - no matter how much you illuminate, there's always a smaller but darker one. #quote
|
||||
|
||||
The above quote is attributed to Brian Kernighan (one of the authors of the [[C]] K&R book).
|
||||
|
||||
|
@ -83,4 +83,111 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202
|
|||
<!--ID: 1706726911454-->
|
||||
END%%
|
||||
|
||||
[^robbins]: 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)
|
||||
%%ANKI
|
||||
Basic
|
||||
Write the `awk` command that searches file `mail-list` for string `li`.
|
||||
Back:
|
||||
```bash
|
||||
$ awk '/li/ { print }' mail-list
|
||||
```
|
||||
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: 1706819150999-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is an `awk` rule without a pattern interpreted?
|
||||
Back: As applying the specified action for every input line.
|
||||
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: 1706822165633-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is an `awk` rule without an action interpreted?
|
||||
Back: As printing every line matching the specified pattern.
|
||||
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: 1706822165637-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Describe what the following command does in in a single sentence:
|
||||
```bash
|
||||
$ awk 'length($0) > 80' data
|
||||
```
|
||||
Back: Prints every line of `data` that is longer than `80` characters.
|
||||
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: 1706822165641-->
|
||||
END%%
|
||||
|
||||
**Targets** are specified as `$n` where `n` is a placeholder for the `n`th whitespace-separated **field**s of the input line. For example, `$1` refers to the first field of the input line. `$0` is a special target referring to the entire list of arguments, i.e. the entire line.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is `$0` a placeholder for?
|
||||
Back: The entire input line.
|
||||
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: 1706823790230-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is `$1` a placeholder for?
|
||||
Back: The first field of the input line.
|
||||
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: 1706823790233-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the `BEGIN` pattern?
|
||||
Back: Code associated with it executes before any input is read.
|
||||
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: 1706823790236-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the `END` pattern?
|
||||
Back: Code associated with it executes after all input has been read.
|
||||
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: 1706823790239-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Describe what the following command does in in a single sentence:
|
||||
```bash
|
||||
$ awk 'NF > 0' data
|
||||
```
|
||||
Back: Prints every line of `data` with at least one 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)
|
||||
<!--ID: 1706823927382-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Describe what the following command does in in a single sentence:
|
||||
```bash
|
||||
$ awk 'END { print NR }' data
|
||||
```
|
||||
Back: Prints the number of lines in `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: 1706824091124-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Describe what the following command does in in a single sentence:
|
||||
```bash
|
||||
$ awk 'NR % 2 == 0' data
|
||||
```
|
||||
Back: Prints every even-numbered line in `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: 1706824091128-->
|
||||
END%%
|
||||
|
||||
## 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)
|
|
@ -7,7 +7,9 @@ tags:
|
|||
- signal
|
||||
---
|
||||
|
||||
This is an overview of specific POSIX signals.[^dowling]
|
||||
## Overview
|
||||
|
||||
This is an overview of specific POSIX signals.
|
||||
|
||||
Code | Name
|
||||
----- | --------------
|
||||
|
@ -112,4 +114,33 @@ Reference: `man 1 ps`
|
|||
<!--ID: 1706670390919-->
|
||||
END%%
|
||||
|
||||
[^dowling]: Dowling, “A List of Signals and What They Mean.”
|
||||
### SIGINT (2)
|
||||
|
||||
Indicates the process was interrupted by the user. Happens when pressing `Ctrl-C` from the controlling terminal.
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
Signal {`SIGINT`} corresponds to number {2}.
|
||||
Reference: Dowling, “A List of Signals and What They Mean.”
|
||||
<!--ID: 1706815743860-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What control sequence usually triggers a `SIGINT`?
|
||||
Back: `Ctrl-C`
|
||||
Reference: Dowling, “A List of Signals and What They Mean.”
|
||||
<!--ID: 1706815743867-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the `INT` in `SIGINT` short for?
|
||||
Back: **Int**errupt
|
||||
Reference: Dowling, “A List of Signals and What They Mean.”
|
||||
<!--ID: 1706815743870-->
|
||||
END%%
|
||||
|
||||
## References
|
||||
|
||||
* Dowling, “A List of Signals and What They Mean.”
|
||||
|
|
Loading…
Reference in New Issue