wc (Unix)

{{Short description|Unix command utility}}

{{lowercase}}

{{Infobox software

| name = wc

| logo =

| screenshot = Wc-unix.png

| screenshot size =

| caption = The {{code|wc}} command

| author = Joe Ossanna
(AT&T Bell Laboratories)

| developer = Various open-source and commercial developers

| released = {{Start date and age|1971|11|3}}

| latest release version =

| latest release date =

| programming language = C

| operating system = Unix, Unix-like, V, Plan 9, Inferno, MSX-DOS, IBM i

| platform = Cross-platform

| genre = Command

| license = Plan 9, Inferno: MIT
coreutils: GPL-3.0-or-later

| website =

}}

{{code|wc}} (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:

$ wc foo bar

40 149 947 foo

2294 16638 97724 bar

2334 16787 98671 total

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 bar{{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 characters{{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:

$ grep -r "example" |wc

1071 23337 101349

History

{{code|wc}} 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.{{man|cu|wc|SUS}} It appeared in Version 1 Unix.{{man|1|wc|FreeBSD}}

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.{{cite web |url=https://linux.die.net/man/1/wc |title = wc(1) - Linux man page}}

A wc command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.[https://archive.org/details/MSXDOS2TOOLS MSX-DOS2 Tools User's Manual by ASCII Corporation]

The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project[http://gnuwin32.sourceforge.net/packages/coreutils.htm CoreUtils for Windows] and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[http://unxutils.sourceforge.net/ Native Win32 ports of some GNU utilities]

The {{Mono|wc}} command has also been ported to the IBM i operating system.{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=IBM |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}

Usage

  • wc -c prints the byte count
  • wc -l prints the line count
  • wc -m prints the character count
  • wc -w prints the word count
  • wc -L prints the length of the longest line (GNU extension)

See also

References

{{Reflist}}