diff options
author | johannst <johannes.stoelp@gmail.com> | 2020-03-17 23:48:21 +0100 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2020-03-17 23:48:21 +0100 |
commit | fb719f52b73920fb18c7f3080ebb1fc73300be49 (patch) | |
tree | 6e71c03f2acf38e9611bd0c80ac11188056f621c /src | |
parent | 62c9575f7827fb44f24b90a8f8c9d4f1f9f8f1c7 (diff) | |
download | notes-fb719f52b73920fb18c7f3080ebb1fc73300be49.tar.gz notes-fb719f52b73920fb18c7f3080ebb1fc73300be49.zip |
added awk
Diffstat (limited to 'src')
-rw-r--r-- | src/SUMMARY.md | 1 | ||||
-rw-r--r-- | src/awk.md | 44 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 7f385d7..fe0b341 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -2,6 +2,7 @@ - [ld.so](./ld.so.md) - [git](./git.md) +- [awk](./awk.md) - [gdb](./gdb.md) - [radare2](./radare2.md) - [emacs](./emacs.md) diff --git a/src/awk.md b/src/awk.md new file mode 100644 index 0000000..0186416 --- /dev/null +++ b/src/awk.md @@ -0,0 +1,44 @@ +# awk(1) + +```markdown +awk [opt] program [input] + -F <sepstr> field separator string (can be regex) + program awk program + input file or stdin if not file given +``` + +## Input processing + +Input is processed in two stages: +1. Splitting input into a sequence of `records`. + By default split at `newline` character, but can be changed via the + builtin `RS` variable. +2. Splitting a `record` into `fields`. By default strings without `whitespace`, + but can be changed via the builtin variable `FS` or command line option + `-F`. + +Field are accessed as follows: +- `$0` whole `record` +- `$1` field one +- `$2` field two +- ... + +## Program + +An `awk` program is composed of pairs of the form: +```markdown +pattern { action } +``` +The program is run against each `record` in the input stream. If a `pattern` +matches a `record` the corresponding `action` is executed and can access the +`fields`. + +```markdown +INPUT + | + v +record ----> ∀ pattern matched + | | + v v +fields ----> run associated action +``` |