What is the structure of an `awk` program?
BeginnerConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
awk 'pattern { action }' file: for each input line (record), split into fields $1..$NF (by whitespace or -F), and run the action when the pattern is true. BEGIN runs before input, END after.
awk -F: '$3 >= 1000 && $7 !~ /nologin/ {print $1, $6}' /etc/passwd
awk '{bytes += $10} END {printf "%.1f MB\n", bytes / 1024 / 1024}' access.log
awk 'NR > 1 && $5+0 > 80 {print $6, $5}' <(df -P)
Built-ins worth knowing: NR (record number), NF (field count), $NF (last field), FS/OFS, FILENAME.
More on Text processing: grep, sed, awk, cut, sort, uniq
What are the most useful `grep` flags?BeginnerWhat is the difference between basic, extended and Perl regular expressions in grep?IntermediateWhat are the core `sed` commands you use in automation?BeginnerWhy does `sed -i` behave differently on macOS and Linux?IntermediateHow do you use variables inside a `sed` expression safely?AdvancedHow do you count occurrences per key with `awk` associative arrays?Intermediate