NAME
wc — word, line,
and byte count
SYNOPSIS
wc |
[-clw] [file
...] |
DESCRIPTION
The wc utility shall read one or more
input files and, by default, write the number of <newline>s, words,
and bytes contained in each input file to the standard output. The utility
also shall write a total count for all named files, if more than one input
file is specified. The wc utility shall consider a
word to be a nonzero-length string of characters delimited by white
space.
OPTIONS
The wc utility shall conform to the
utility argument syntax guidelines described in 2.10.2. The following
options shall be supported by the implementation:
-c-
Write to the standard output the number of bytes in each input file.
-l-
Write to the standard output the number of <newline>s in each input file.
-w-
Write to the standard output the number of words in each input file. When any option is specified,
wcshall report only the information requested by the specified option(s).
OPERANDS
The following operand shall be supported by the implementation:
- file
-
A pathname of an input file. If no file operands are specified, the standard input shall be used.
STANDARD INPUT
The standard input shall be used only if no file operands are specified. See Input Files.
INPUT FILES
The input files may be of any type.
ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of
wc:
LANG-
This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_ ) do not specify a locale. See 2.6.
LC_ALL-
This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_.
LC_CTYPE-
This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments and input files) and which characters are defined as ‘‘white space’’ characters.
LC_MESSAGES-
This variable shall determine the language in which messages should be written.
ASYNCHRONOUS EVENTS
Default.
STANDARD OUTPUT
By default, the standard output shall contain a line for each input file of the form: "%d %d %d %s\n", <newlines>, <words>, <bytes>, <file> If any options are specified and the −l option is not specified, the number of <newline>s shall not be written.
If any options are specified and the −w option is not specified, the number of words shall not be written. If any options are specified and the −c option is not specified, the number of bytes shall not be written. If no input file operands are specified, no name shall be written and no <blank>s preceding the pathname shall be written. If more than one input file operand is specified, an additional line shall be written, of the same format as the other lines, except that the word total (in the POSIX Locale) shall be written instead of a pathname and the total of each column shall be written as appropriate. Such an additional line, if any, shall be written at the end of the output.
STANDARD ERROR
Used only for diagnostic messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
None.
EXIT STATUS
The wc utility shall exit with one of the
following values:
CONSEQUENCES OF ERRORS
Default.
RATIONALE
EXAMPLES
None.
HISTORY OF DECISIONS MADE
The output file format pseudo- printf(3) string
was derived from the HP-UX version of wc; the System
V version: "%7d%7d%7d %s\n" produces possibly ambiguous and
unparsable results for very large files, as it assumes no number will exceed
six digits. Some historical implementations use only <space>,
<tab>, and <newline> as word separators. The equivalent of the C
Standard {7}
isspace()
function is more appropriate. The −c option stands for
‘‘character’’ count, even though it counts
bytes. This stems from the sometimes erroneous historical view that bytes
and characters are the same size. Earlier drafts only specified the results
when input files were text files. The current specification more closely
matches existing practice. (Bytes, words, and <newline>s are counted
separately and the results are written when an end-offile is detected.)
Historical implementations of the wc utility only
accepted one argument to specify the options −c, −l, and
−w. Some of them also had multiple occurrences of an option cause the
corresponding count to be output multiple times and having the order of
specification of the options affect the order of the fields on output, but
did not document either of these. Because common usage either specifies no
options or only one option and because none of this was documented, the
changes required by this standard should not break many existing
applications (and does not break any historical portable applications.)