8.4.39 wc command (counts the number of bytes, lines, characters, and words in files)
Syntax
wc [-c] [-l] [-m] [-w] [path-name ...]
Description
This command counts the number of bytes, lines, characters, and words in files. Depending on the options that are specified, the counts of the numbers of lines, words, characters, and bytes are displayed in front of the name of each input file.
Arguments
- -c
Specifies that the number of bytes in an input file is to be output to the standard output.
- -l
Specifies that the number of lines in an input file is to be output to the standard output. The number of lines is determined by the number of end-of-line codes.
- -m
Specifies that the number of characters in an input file is to be output to the standard output. A multibyte character is counted as a single character.
- -w
Specifies that the number of words in an input file is to be output to the standard output. The number of words is determined by the number of character strings delimited by a space, tab, or end-of-line code.
- path-name
Specifies the name of an input file. If path-name is not specified or is specified as -, the standard input is read.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 or greater |
Error termination |
Notes
Any character in a character encoding that is different from the local character encoding is considered an invalid or incomplete character.
Specifying no option is equivalent to specifying the -c, -l, and -w options.
Regardless of the order in which the options are specified, output items are displayed in the order of lines-count, words-count, multibyte-characters-count, bytes-count, and file-name. Numeric values are displayed as seven-digit numbers separated by a single space. The number of digits is increased if necessary to accommodate values that exceed seven digits.
An error results if an input file contains invalid or incomplete multibyte or wide characters, binary data, or a character encoding that is different from the local character encoding. In these cases, an error message (wc: binaryfile: Invalid or incomplete multibyte or wide character) is output.
Examples
Display the default with no options specified.
C:\TEMP>%ADSH_OSCMD_DIR%\wc a.txt b.txt 5 5 55 a.txt 4 4 44 b.txt 9 9 99 total
Specify the -c option to display the number of bytes in the input file.
C:\TEMP>%ADSH_OSCMD_DIR%\wc -c a.txt 55 a.txt
Specify the -l option to display the number of lines in the input file.
C:\TEMP>%ADSH_OSCMD_DIR%\wc -l a.txt 5 a.txt
Specify the -m option to display the number of characters in the input file.
C:\TEMP>%ADSH_OSCMD_DIR%\wc -m a.txt 50 a.txt
Specify the -w option to display the number of words in the input file.
C:\TEMP>%ADSH_OSCMD_DIR%\wc -w a.txt 5 a.txt
Specify all the options to display the number of lines, words, characters, and bytes in the input file.
C:\TEMP>%ADSH_OSCMD_DIR%\wc -clmw a.txt 5 5 50 55 a.txt
Display an option error message.
This message might vary depending on the platform on which the command is executed. The following shows an example in Windows:
C:\TEMP>%ADSH_OSCMD_DIR%\wc -z wc: illegal option -- z usage: wc [-clmw] [file ...]
Display the error message that is output when there is an invalid or incomplete character in the file.
C:\TEMP>%ADSH_OSCMD_DIR%\wc binaryfile wc: binaryfile: Invalid or incomplete multibyte or wide character
The following are considered invalid or incomplete characters:
Invalid or incomplete multibyte or wide characters, or binary data
Characters in a character encoding that is different from the local character encoding