Skip to content

Commit 97a228c

Browse files
committed
why awk -F is useful
1 parent f262523 commit 97a228c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

pages/awk___-F.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
- # [[awk]] `-F` — field separator flag
1+
# [[awk]] `-F` — field separator flag
22
- `-F` sets the **field separator** (`FS`) used to split each input line into fields.
3+
- [[My Note]] by default the field separator is any whitespace (space or tab chars). `awk -F` is useful if you need to customize that some more.
34
- ## Syntax
45
- ~~~bash
56
awk -F'<sep>' '{ ... }' file
67
~~~
78
- `<sep>` can be a literal character or an ERE (extended regular expression).
89
- ## How it works
9-
- Without `-F`, `awk` splits on runs of whitespace (spaces and tabs, collapsing consecutive ones).
10+
- Without `-F`, `awk` splits on **runs of whitespace** (spaces and tabs, collapsing consecutive ones).
1011
- With `-F`, each line is split on the given separator; fields are referenced as `$1`, `$2`, ... `$NF`.
1112
- The field separator is also available as the built-in variable `FS`; `-F'\t'` is equivalent to `BEGIN { FS = "\t" }`.
1213
- ## Common examples
@@ -27,4 +28,4 @@
2728
- `obsidian hotkeys` outputs tab-separated lines — command ID in `$1`, key binding in `$2` (empty if unmapped). `-F'\t'` splits on tab; `$2` as a condition passes only lines where the second field is non-empty:
2829
- ~~~bash
2930
obsidian hotkeys | awk -F'\t' '$2'
30-
~~~
31+
~~~

0 commit comments

Comments
 (0)