awk one-liners: extract and filter columns from any output
Use awk '{print $n}' with -F and conditions to slice columns and filter rows on Linux.
Run awk '{print $2, $5}' FILE (add -F, for comma-delimited data) to print chosen fields, with conditions like '$3>10' to filter rows.
01Command
Command
$ df -h | awk 'NR>1 {print $6, $5}' && ps aux | awk '$3>10 {print $11}'02What it does
awk treats every input line as whitespace-split fields $1 through $NF, so printing column 2 is just {print $2} — no regex needed. The -F flag changes the separator (CSV, colons in /etc/passwd), conditions before the braces act as row filters, NR>1 skips headers, and $NF always means the last field. It combines cutting, grep-filtering and formatting in one process, which is why one awk line replaces a pipeline of three commands.
03Risk
!Warning: Default splitting collapses runs of whitespace; for single-space-significant data use -F ' ' with an explicit regex.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- AWK — ArchWikiEvidence: Community examples of field extraction one-liners with print $n and conditions
- awk(1P) — POSIX manual pageEvidence: Documents field variables $1..$NF, pattern-action pairs and the -F field separator
Last verified: 2026-09-17 · Category: Files & Folders