awk -F: Set the Input Field Separator
awk -F sets the character or regex that separates fields, so $1, $2 line up with the columns you mean.
CSV, colon-separated configs, and tab-delimited output all need a non-default separator. -F on the command line and FS inside the program both control it.
What it does
By default awk splits on runs of whitespace. -F <sep> or setting FS changes the separator to a single character (like , or :) or a regex. The separator applies when each line is read into fields.
Common usage
# comma-separated: print the 3rd column
awk -F, '{print $3}' data.csv
# colon-separated: usernames from /etc/passwd
awk -F: '{print $1}' /etc/passwd
# tab-separated (literal tab)
awk -F'\t' '{print $2}' report.tsv
# regex separator: one or more spaces or commas
awk -F'[ ,]+' '{print $2}' mixed.txtSeparator forms
| Form | What it does |
|---|---|
| -F, | Split on a comma |
| -F: | Split on a colon |
| -F'\t' | Split on a tab character |
| -F'[ ,]+' | Split on a regex: runs of spaces or commas |
| BEGIN{FS=","} | Set the separator in the program instead of on the flag |
| FS=" " (default) | Special case: split on any run of whitespace, trim leading/trailing |
In CI
For real CSV with quoted commas, awk -F, is not enough because it splits inside quotes; use a CSV-aware parser there. For simple machine output (colon, tab, fixed columns) -F is exactly right and avoids pulling in extra tools on the runner.
Common errors in CI
A regex separator with special characters needs care: -F. splits on every character because . is "any char"; use -F'[.]' or -F'\\.' for a literal dot. Setting FS inside the main block instead of BEGIN means it only takes effect on the next line, so the first line is mis-split. With the default FS, leading whitespace is trimmed, so $1 is the first non-blank field.