How to Count and Cut Text with wc and cut
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.
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.
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.
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 characters with -c
To take specific character positions instead of fields, use -c. cut -c1-10 prints the first ten characters of each line.
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.