wc(1)
NAME
wc − word, line, and byte or character count
SYNOPSIS
wc [-c|-m] [-lw] [names]
DESCRIPTION
The wc command counts lines, words, and bytes or characters in the named files, or in the standard input if no names are specified. It also keeps a total count for all named files.
A word is a maximal string of characters delimited by spaces, tabs, or new-lines.
wc recognizes the following command-line options:
-c Write to the standard output the number of bytes in each input file.
-m Write to the standard output the number of characters in each input file.
-w Write to the standard output the number of words in each input file.
-l Write to the standard output the number of newline characters in each input file.
The c and m options are mutually exclusive. Otherwise, the l, w, and c or m options can be used in any combination to specify that a subset of lines, words, and bytes or characters are to be reported.
When any option is specified, wc will report only the information requested by the specified options. If no option is specified, The default output is -lwc.
When names are specified on the command line, they are printed along with the counts.
EXTERNAL INFLUENCES
Environment Variables
LC_CTYPE determines the range of graphics and space characters, and the interpretation of text as single- and/or multi-byte characters.
LC_MESSAGES determines the language in which messages are displayed.
If LC_CTYPE or LC_MESSAGES is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG.
If any internationalization variable contains an invalid setting, wc behaves as if all internationalization variables are set to "C". See environ(5).
International Code Set Support
Single- and multi-byte character code sets are supported.
WARNINGS
The wc command counts the number of newlines to determine the line count. If a text file has a final line that is not terminated with a newline character, the count will be off by one.
Standard Output (XPG4 only)
By default, the standard output contains an entry for each input file of the form:
"%d %d %d %s\n", <newlines>, <words>, <bytes>, <file>
If the -m option is specified, the number of characters replaces the <bytes> field in this format.
If any options are specified and the -l option is not specified, the number of newlines are not written.
If any options are specified and the -w option is not specified, the number of words are not written.
If any options are specified and neither -c nor -m is specified, the number of bytes or characters are not written.
If no input file operands are specified, no flie name is written and no blank characters preceding the pathname is written.
If more than one input file operand is specified, an additional line is written, of the same format as the other lines, except that the word total (in the POSIX Locale) is written instead of a pathname and the total of each column is written as appropriate. Such an additional line, if any, is written at the end of the input.
Exit Status
The wc utility shall exit with one of the following values
0 Successful completion.
>0 An error occured.
EXAMPLES
Print the number of words and characters in file1:
wc -wm file1
The following is printed when the above command is executed:
n1 n2 file1
where n1 is the number of words and n2 is the number of characters in file1.
STANDARDS CONFORMANCE
wc: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
Hewlett-Packard Company — HP-UX Release 10.20: July 1996