wc counts the number of lines, words and characters contained in files and writes the results to standard output.
Syntax
wc[ -c| -m][ -lw][ file...] |
No option specified wc outputs three numeric values for the number of lines, words, and characters. option
wc outputs the number of bytes. Spaces, tabs and newline characters are counted. The option -c acts exactly like the option -m since one byte corresponds to one character.
wc outputs the number of characters. Spaces, tabs and newline characters are counted. The option -m acts exactly like the option -c since one character corresponds to one byte.
Reports the number of lines, based on the number of newline characters counted by wc.
Reports the number of words. A word is defined as a non-empty string delimited by whitespace characters. Whitespace characters are blanks, tabs and newline characters.
Name of the file whose lines, words, and characters are to be counted. The file name will be printed along with the counts. file not specified: |
Locale
The following environment variables affect the execution of wc: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_CTYPE defines which characters are treated as whitespace characters. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example 1
Listing line, word, and character counts for the files logic, plan and rem.
|
Example 2
Checking the number of files in the current directory.
|
Example 3
Checking the number of users working on the system.
|
Example 4
Counting the number of unique words in a file.
Explanation: sed creates a list of all words in file by replacing one or more blanks by newline characters. sort -u sorts this list, removing all repetitions. wc -l then counts the lines in this list and prints the total. |