wc count lines, words and bytes
wc (word count) reports how many lines, words and bytes are in its input. Most of the time you want wc -l, the number of lines.
Availability Preinstalled on macOS, Linux and BSD
Syntax
wc [-l] [-w] [-c] [-m] [file ...]
Common options
| Option | What it does |
|---|---|
-l | Count lines |
-w | Count words |
-c | Count bytes |
-m | Count characters (differs from bytes for non-ASCII text) |
Examples
Lines in a file
wc -l users.csv
Lines in many files, with a total
wc -l *.csv
Use wc with sqx
Count the rows a query returns
With -o raw there is no header, so every line is one row.
sqx -f users=users.csv -o raw "SELECT email FROM users WHERE plan = 'pro'" | wc -l
Or count inside SQL
COUNT(*) is exact and ignores the header row, which wc -l would include.
sqx -f users=users.csv "SELECT COUNT(*) FROM users WHERE plan = 'pro'"
Full documentation
This page covers the essentials. For every option, see the official documentation:
Or read the manual in your terminal: man wc