awk Commands
Pattern scanning and text processing language.All awk pages
- awk '!seen[$0]++': remove duplicate lines without sortingawk '!seen[$0]++' removes duplicate lines and keeps the original order, no sorting needed. Deduplicate by one column, ignore case, and the memory trade-off.
- awk '{print $2}': print a specific columnawk '{print $2}' prints the second whitespace-separated field of each line. Use -F for other separators, $NF for the last column and OFS for the output.
- awk '$3 > 100': filter rows by a column valueawk -F, '$3 > 100' prints rows whose third column is over 100. Exact matches with ==, regex with ~, combined conditions, -v thresholds, text vs number traps.
- awk sum a column: awk '{ s += $2 } END { print s }'Sum a column with awk: awk '{ s += $2 } END { print s }' file. Set -F for CSV, skip the header with NR > 1, group totals by key with an array, print decimals.