1WC(1P) POSIX Programmer's Manual WC(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 wc - word, line, and byte or character count
13
15 wc [-c|-m][-lw][file...]
16
18 The wc utility shall read one or more input files and, by default,
19 write the number of <newline>s, words, and bytes contained in each
20 input file to the standard output.
21
22 The utility also shall write a total count for all named files, if more
23 than one input file is specified.
24
25 The wc utility shall consider a word to be a non-zero-length string of
26 characters delimited by white space.
27
29 The wc utility shall conform to the Base Definitions volume of
30 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
31
32 The following options shall be supported:
33
34 -c Write to the standard output the number of bytes in each input
35 file.
36
37 -l Write to the standard output the number of <newline>s in each
38 input file.
39
40 -m Write to the standard output the number of characters in each
41 input file.
42
43 -w Write to the standard output the number of words in each input
44 file.
45
46
47 When any option is specified, wc shall report only the information
48 requested by the specified options.
49
51 The following operand shall be supported:
52
53 file A pathname of an input file. If no file operands are specified,
54 the standard input shall be used.
55
56
58 The standard input shall be used only if no file operands are speci‐
59 fied. See the INPUT FILES section.
60
62 The input files may be of any type.
63
65 The following environment variables shall affect the execution of wc:
66
67 LANG Provide a default value for the internationalization variables
68 that are unset or null. (See the Base Definitions volume of
69 IEEE Std 1003.1-2001, Section 8.2, Internationalization Vari‐
70 ables for the precedence of internationalization variables used
71 to determine the values of locale categories.)
72
73 LC_ALL If set to a non-empty string value, override the values of all
74 the other internationalization variables.
75
76 LC_CTYPE
77 Determine the locale for the interpretation of sequences of
78 bytes of text data as characters (for example, single-byte as
79 opposed to multi-byte characters in arguments and input files)
80 and which characters are defined as white space characters.
81
82 LC_MESSAGES
83 Determine the locale that should be used to affect the format
84 and contents of diagnostic messages written to standard error
85 and informative messages written to standard output.
86
87 NLSPATH
88 Determine the location of message catalogs for the processing of
89 LC_MESSAGES .
90
91
93 Default.
94
96 By default, the standard output shall contain an entry for each input
97 file of the form:
98
99
100 "%d %d %d %s\n", <newlines>, <words>, <bytes>, <file>
101
102 If the -m option is specified, the number of characters shall replace
103 the <bytes> field in this format.
104
105 If any options are specified and the -l option is not specified, the
106 number of <newline>s shall not be written.
107
108 If any options are specified and the -w option is not specified, the
109 number of words shall not be written.
110
111 If any options are specified and neither -c nor -m is specified, the
112 number of bytes or characters shall not be written.
113
114 If no input file operands are specified, no name shall be written and
115 no <blank>s preceding the pathname shall be written.
116
117 If more than one input file operand is specified, an additional line
118 shall be written, of the same format as the other lines, except that
119 the word total (in the POSIX locale) shall be written instead of a
120 pathname and the total of each column shall be written as appropriate.
121 Such an additional line, if any, is written at the end of the output.
122
124 The standard error shall be used only for diagnostic messages.
125
127 None.
128
130 None.
131
133 The following exit values shall be returned:
134
135 0 Successful completion.
136
137 >0 An error occurred.
138
139
141 Default.
142
143 The following sections are informative.
144
146 The -m option is not a switch, but an option at the same level as -c.
147 Thus, to produce the full default output with character counts instead
148 of bytes, the command required is:
149
150
151 wc -mlw
152
154 None.
155
157 The output file format pseudo- printf() string differs from the System
158 V version of wc:
159
160
161 "%7d%7d%7d %s\n"
162
163 which produces possibly ambiguous and unparsable results for very large
164 files, as it assumes no number shall exceed six digits.
165
166 Some historical implementations use only <space>, <tab>, and <newline>
167 as word separators. The equivalent of the ISO C standard isspace()
168 function is more appropriate.
169
170 The -c option stands for "character" count, even though it counts
171 bytes. This stems from the sometimes erroneous historical view that
172 bytes and characters are the same size. Due to international require‐
173 ments, the -m option (reminiscent of "multi-byte") was added to obtain
174 actual character counts.
175
176 Early proposals only specified the results when input files were text
177 files. The current specification more closely matches historical prac‐
178 tice. (Bytes, words, and <newline>s are counted separately and the
179 results are written when an end-of-file is detected.)
180
181 Historical implementations of the wc utility only accepted one argument
182 to specify the options -c, -l, and -w. Some of them also had multiple
183 occurrences of an option cause the corresponding count to be written
184 multiple times and had the order of specification of the options affect
185 the order of the fields on output, but did not document either of
186 these. Because common usage either specifies no options or only one
187 option, and because none of this was documented, the changes required
188 by this volume of IEEE Std 1003.1-2001 should not break many historical
189 applications (and do not break any historical conforming applications).
190
192 None.
193
195 cksum
196
198 Portions of this text are reprinted and reproduced in electronic form
199 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
200 -- Portable Operating System Interface (POSIX), The Open Group Base
201 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
202 Electrical and Electronics Engineers, Inc and The Open Group. In the
203 event of any discrepancy between this version and the original IEEE and
204 The Open Group Standard, the original IEEE and The Open Group Standard
205 is the referee document. The original Standard can be obtained online
206 at http://www.opengroup.org/unix/online.html .
207
208
209
210IEEE/The Open Group 2003 WC(1P)