aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/awk.md
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/awk.md')
-rw-r--r--src/tools/awk.md7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/tools/awk.md b/src/tools/awk.md
index 38b0cb1..f8aa0a8 100644
--- a/src/tools/awk.md
+++ b/src/tools/awk.md
@@ -59,6 +59,7 @@ multiple times. Actions with those patterns are **executed exactly once**.
- `FS` _field separator_: regex to split records into fields, by default
<space>
- `NR` _number record_: number of current record
+- `NF` _number fields_: number of fields in the current record
### Special statements & functions
@@ -96,6 +97,12 @@ awk 'NR%2 == 0 { print $0 }' <file>
The pattern `NR%2 == 0` matches every second record and the action `{ print $0 }`
prints the whole record.
+### Access last fields in records
+```bash
+echo 'a b c d e f' | awk '{ print $NF $(NF-1) }'
+```
+Access last fields with arithmetic on the `NR` number of fields variable.
+
### Capture in variables
```bash
# /proc/<pid>/status