Previous | Table of Contents | Next |
DESCRIPTION
The external wc command counts the characters, words, and lines in a file and displays the output on your screen. The word delimeters for wc are space, tab, and new-line. The delimeter for a line is new-line. The input may be the standard input, therefore wc is a filter.
The features of wc are:
COMMAND FORMAT
Following is the general format of the wc command.
wc [ -clw ] [ file_list ]
Options
The following options may be used to control how wc functions.
-c | Count and display only the number of characters contained in the given files. |
-l | Count and display only the number of lines contained in the given files. Lines are defined as ending with new-lines. |
-w | Count and display only the number of words contained in the given files. Words are defined as ending with spaces, tabs, or new-lines. |
If no options are specified, wc returns the count for lines, words, and characters. Thus wc assumes the -lwc options. | |
The counts are displayed in the order the options are given. For instance, if you specify -cwl, wc displays characters, words, and lines followed by the filename. |
Arguments
The following argument may be passed to the wc command.
file_list | One or more files to be counted. The requested counts will be displayed. Each filename will be displayed on a line by itself, preceded by the appropriate counts. |
If no files are given, then wc reads from the standard input, which may be a pipe, indirection, or your keyboard. |
APPLICATIONS
You use wc to show the size of a file. It is commonly used to count how many lines are in a text document. It may be useful when handling flat ASCII files that are databases. Using wc, you can list how many entries exist in your database. It is also used to count the entries in a directory. The basic rule is, if it's ASCII text and you want to know how many lines, words, or characters are in a file, you use the wc command.
TYPICAL OPERATION
In this activity you use the wc command to count the lines in a file and the number of entries in a directory. Begin at the shell prompt.
cj> wc /etc/group 12 12 1172 /etc/group
cj> wc -w < /etc/passwd 363
Previous | Table of Contents | Next |