How to Count and Cut Text with wc and cut

Published 2026-08-05 · Learn Linux

The wc command counts lines, words and bytes, and the cut command extracts columns from delimited text. wc -l file.txt prints the line count, and cut -d: -f1 file pulls the first field from each colon-separated line. Both are lightweight staples for quick text work.

Count lines, words and bytes with wc

Plain wc prints all three counts: lines, words and bytes. The flags isolate one: -l lines, -w words, -c bytes.

$ wc -l app.log
$ wc -w report.txt

Count lines of command output

Pipe any command into wc to count its lines. ls | wc -l counts files, and ps aux | wc -l counts processes.

$ ls | wc -l

Cut fields with cut -f

cut splits each line at a delimiter and prints the fields you ask for. The default delimiter is the tab character. -f1,3 prints fields 1 and 3.

$ cut -f1 data.tsv

Change the delimiter with -d

For comma- or colon-separated data, set the delimiter with -d. This pulls the first field from every line of /etc/passwd:

$ cut -d: -f1 /etc/passwd

Cut characters with -c

To take specific character positions instead of fields, use -c. cut -c1-10 prints the first ten characters of each line.

$ cut -c1-10 log.txt

For richer column work see awk. The wc and cut reference pages list all options.

Keep learning

Related guides: How to Sort and Deduplicate Text with sort and uniq · awk: The Linux Text Processing Tool Explained · How to View File Starts and Ends with head and tail. Read all tutorials on the Learn Linux blog.