Wc (Unix)
Template:Short description Template:Lowercase {{#invoke:Infobox|infobox}}Template:Template other {{#invoke:Check for unknown parameters|check|unknown=Template:Main other|preview=Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y| AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo class | logo size | logo title | logo upright | logo_alt | logo_caption | logo_class | logo_size | logo_title | logo_upright | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | qid | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot class | screenshot size | screenshot title | screenshot upright | screenshot_alt | screenshot_class | screenshot_size | screenshot_upright | service_name | size | standard | title | ver layout | website }}Template:Main other <syntaxhighlight lang="text" class="" style="" inline="1">wc</syntaxhighlight> (short for word count) is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.
Example
Sample execution of wc:
<syntaxhighlight lang="console">
$ wc foo bar
40 149 947 foo
2294 16638 97724 bar
2334 16787 98671 total
</syntaxhighlight>
The first column is the count of newlines, meaning that the text file foo has 40 newlines while bar has 2294 newlines- resulting in a total of 2334 newlines. The second column indicates the number of words in each text file showing that there are 149 words in foo and 16638 words in barTemplate:Snd giving a total of 16787 words. The last column indicates the number of characters in each text file, meaning that the file foo has 947 characters while bar has 97724 charactersTemplate:Snd 98671 characters all in all.
Newer versions of wc can differentiate between byte and character count. This difference arises with Unicode which includes multi-byte characters. The desired behaviour is selected with the -c or -m options.
Through a pipeline, it can also be used to preview the output size of a command with a potentially large output, without it printing the text into the console: <syntaxhighlight lang=console> $ grep -r "example" |wc
1071 23337 101349
</syntaxhighlight>
History
<syntaxhighlight lang="text" class="" style="" inline="1">wc</syntaxhighlight> is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification.<ref>Template:Man</ref> It appeared in Version 1 Unix.<ref>Template:Man</ref>
GNU wc used to be part of the GNU textutils package; it is now part of GNU coreutils. The version of wc bundled in GNU coreutils was written by Paul Rubin and David MacKenzie.<ref>{{#invoke:citation/CS1|citation
|CitationClass=web
}}</ref>
A wc command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.<ref>MSX-DOS2 Tools User's Manual by ASCII Corporation</ref>
The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project<ref>CoreUtils for Windows</ref> and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.<ref>Native Win32 ports of some GNU utilities</ref>
The Template:Mono command has also been ported to the IBM i operating system.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
Usage
wc -c <filename>prints the byte countwc -l <filename>prints the line countwc -m <filename>prints the character countwc -w <filename>prints the word countwc -L <filename>prints the length of the longest line (GNU extension)
See also
References
External links
- wc(1) - Original Unix First Edition manual page for wc.
- Template:Man
- Template:Man
- Template:Man
- The
wcCommand by The Linux Information Project (LINFO)
Template:Unix commands Template:Plan 9 commands Template:Core Utilities commands