From 2a064a9d1bbb8de6ce489b685cce026eee167cd2 Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 17 Mar 2020 22:48:49 +0000 Subject: deploy: fb719f52b73920fb18c7f3080ebb1fc73300be49 --- awk.html | 257 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 awk.html (limited to 'awk.html') diff --git a/awk.html b/awk.html new file mode 100644 index 0000000..3f331e8 --- /dev/null +++ b/awk.html @@ -0,0 +1,257 @@ + + + + + + awk - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + +
+
+

awk(1)

+
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. +
  3. Splitting a record into fields. By default strings without whitespace, +but can be changed via the builtin variable FS or command line option +-F.
  4. +
+

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:

+
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.

+
INPUT
+  |
+  v
+record ----> ∀ pattern matched
+  |                   |
+  v                   v
+fields ----> run associated action
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3