1WC(P)                      POSIX Programmer's Manual                     WC(P)
2
3
4

NAME

6       wc - word, line, and byte or character count
7

SYNOPSIS

9       wc [-c|-m][-lw][file...]
10

DESCRIPTION

12       The  wc  utility  shall  read  one or more input files and, by default,
13       write the number of <newline>s, words,  and  bytes  contained  in  each
14       input file to the standard output.
15
16       The utility also shall write a total count for all named files, if more
17       than one input file is specified.
18
19       The wc utility shall consider a word to be a non-zero-length string  of
20       characters delimited by white space.
21

OPTIONS

23       The  wc  utility  shall  conform  to  the  Base  Definitions  volume of
24       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
25
26       The following options shall be supported:
27
28       -c     Write to the standard output the number of bytes in  each  input
29              file.
30
31       -l     Write  to  the  standard output the number of <newline>s in each
32              input file.
33
34       -m     Write to the standard output the number of  characters  in  each
35              input file.
36
37       -w     Write  to  the standard output the number of words in each input
38              file.
39
40
41       When any option is specified, wc  shall  report  only  the  information
42       requested by the specified options.
43

OPERANDS

45       The following operand shall be supported:
46
47       file   A  pathname of an input file. If no file operands are specified,
48              the standard input shall be used.
49
50

STDIN

52       The standard input shall be used only if no file  operands  are  speci‐
53       fied. See the INPUT FILES section.
54

INPUT FILES

56       The input files may be of any type.
57

ENVIRONMENT VARIABLES

59       The following environment variables shall affect the execution of wc:
60
61       LANG   Provide  a  default value for the internationalization variables
62              that are unset or null. (See  the  Base  Definitions  volume  of
63              IEEE Std 1003.1-2001,  Section  8.2,  Internationalization Vari‐
64              ables for the precedence of internationalization variables  used
65              to determine the values of locale categories.)
66
67       LC_ALL If  set  to a non-empty string value, override the values of all
68              the other internationalization variables.
69
70       LC_CTYPE
71              Determine the locale for  the  interpretation  of  sequences  of
72              bytes  of  text  data as characters (for example, single-byte as
73              opposed to multi-byte characters in arguments and  input  files)
74              and which characters are defined as white space characters.
75
76       LC_MESSAGES
77              Determine  the  locale  that should be used to affect the format
78              and contents of diagnostic messages written  to  standard  error
79              and informative messages written to standard output.
80
81       NLSPATH
82              Determine the location of message catalogs for the processing of
83              LC_MESSAGES .
84
85

ASYNCHRONOUS EVENTS

87       Default.
88

STDOUT

90       By default, the standard output shall contain an entry for  each  input
91       file of the form:
92
93
94              "%d %d %d %s\n", <newlines>, <words>, <bytes>, <file>
95
96       If  the  -m option is specified, the number of characters shall replace
97       the <bytes> field in this format.
98
99       If any options are specified and the -l option is  not  specified,  the
100       number of <newline>s shall not be written.
101
102       If  any  options  are specified and the -w option is not specified, the
103       number of words shall not be written.
104
105       If any options are specified and neither -c nor -m  is  specified,  the
106       number of bytes or characters shall not be written.
107
108       If  no  input file operands are specified, no name shall be written and
109       no <blank>s preceding the pathname shall be written.
110
111       If more than one input file operand is specified,  an  additional  line
112       shall  be  written,  of the same format as the other lines, except that
113       the word total (in the POSIX locale) shall  be  written  instead  of  a
114       pathname  and the total of each column shall be written as appropriate.
115       Such an additional line, if any, is written at the end of the output.
116

STDERR

118       The standard error shall be used only for diagnostic messages.
119

OUTPUT FILES

121       None.
122

EXTENDED DESCRIPTION

124       None.
125

EXIT STATUS

127       The following exit values shall be returned:
128
129        0     Successful completion.
130
131       >0     An error occurred.
132
133

CONSEQUENCES OF ERRORS

135       Default.
136
137       The following sections are informative.
138

APPLICATION USAGE

140       The -m option is not a switch, but an option at the same level  as  -c.
141       Thus,  to produce the full default output with character counts instead
142       of bytes, the command required is:
143
144
145              wc -mlw
146

EXAMPLES

148       None.
149

RATIONALE

151       The output file format pseudo- printf() string differs from the  System
152       V version of wc:
153
154
155              "%7d%7d%7d %s\n"
156
157       which produces possibly ambiguous and unparsable results for very large
158       files, as it assumes no number shall exceed six digits.
159
160       Some historical implementations use only <space>, <tab>, and  <newline>
161       as  word  separators.  The  equivalent  of the ISO C standard isspace()
162       function is more appropriate.
163
164       The -c option stands for  "character"  count,  even  though  it  counts
165       bytes.  This  stems  from  the sometimes erroneous historical view that
166       bytes and characters are the same size. Due to  international  require‐
167       ments,  the -m option (reminiscent of "multi-byte") was added to obtain
168       actual character counts.
169
170       Early proposals only specified the results when input files  were  text
171       files.  The current specification more closely matches historical prac‐
172       tice. (Bytes, words, and <newline>s  are  counted  separately  and  the
173       results are written when an end-of-file is detected.)
174
175       Historical implementations of the wc utility only accepted one argument
176       to specify the options -c, -l, and -w. Some of them also  had  multiple
177       occurrences  of  an  option cause the corresponding count to be written
178       multiple times and had the order of specification of the options affect
179       the  order  of  the  fields  on  output, but did not document either of
180       these.  Because common usage either specifies no options  or  only  one
181       option,  and  because none of this was documented, the changes required
182       by this volume of IEEE Std 1003.1-2001 should not break many historical
183       applications (and do not break any historical conforming applications).
184

FUTURE DIRECTIONS

186       None.
187

SEE ALSO

189       cksum
190
192       Portions  of  this text are reprinted and reproduced in electronic form
193       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
194       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
195       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
196       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
197       event of any discrepancy between this version and the original IEEE and
198       The  Open Group Standard, the original IEEE and The Open Group Standard
199       is the referee document. The original Standard can be  obtained  online
200       at http://www.opengroup.org/unix/online.html .
201
202
203
204IEEE/The Open Group                  2003                                WC(P)
Impressum