Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
User Commands (v - z) wc(1)
NAME
wc - Counts lines, words, characters, and bytes
SYNOPSIS
wc [-c | -k | -m][-lw][file ...]
FLAGS
-c Counts bytes.
-k Counts characters.
-m Counts characters.
-l Counts lines.
-w Counts words.
DESCRIPTION
The wc command counts the lines, words, characters, and bytes in a file, or in the standard input
file if you do not specify any files, and writes the results to the standard output file. It also keeps
a total count for all named files.
A word is defined as a nonzero-length string of characters delimited by spaces, tabs, or newline
characters. A line is defined as zero or more characters followed by a newline character.
The wc command counts lines, words, and bytes by default; use the appropriate flags to limit wc
output. Specifying wc without flags is the equivalent of specifying wc -lwc.
The order in which the counts appear in the output line matches the order in which the flags are
entered on the command line. (If you do not specify any flags, the order is lines, words, bytes.)
When you specify more than one file, wc displays the name of the file along with the counts.
EXAMPLES
1. To display the number of lines, words, and bytes in the file text,enter:
wc text
This command results in the following output:
27 185 722 text
The numbers 27, 185, and 722 are the number of lines, words, and bytes, respectively, in
the file text.
2. To display only one or two of the three counts, or to display the counts you want in a par-
ticular order, include the appropriate flags in the order you want. For example, the fol-
lowing command displays only byte and line counts:
wc -cl text
722 27 text
3. To count lines, words, and bytes in more than one file, use wc with more than one input
file or with a filename pattern. For example, the following command can be issued in a
directory containing the files text, text1, and text2:
wc -l text*
27 text
112 text1
5 text2
144 total
527188-007 Hewlett-Packard Company 10−25