Wc (Unix)
Encyclopedia
wc is a command in Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 operating systems.

The program reads either standard input or a list of files and generates one or more of the following statistics: number of bytes, number of words
Word count
The word count is the number of words in a document or passage of text. Word counting may be needed when a text is required to stay within certain numbers of words. This may particularly be the case in academia, legal proceedings, journalism and advertising. Word count is commonly used by...

, and number of lines (specifically, the number of newline
Newline
In computing, a newline, also known as a line break or end-of-line marker, is a special character or sequence of characters signifying the end of a line of text. The name comes from the fact that the next character after the newline will appear on a new line—that is, on the next line below the...

 characters). If a list of files is provided, both individual file and total statistics follow.

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- 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- 98671 characters all in all.

Newer versions of wc can differentiate between byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

 and character
Character (computing)
In computer and machine-based telecommunications terminology, a character is a unit of information that roughly corresponds to a grapheme, grapheme-like unit, or symbol, such as in an alphabet or syllabary in the written form of a natural language....

 count. This difference arises with Unicode
Unicode
Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

 which includes multi-byte characters. The desired behaviour is selected with the -c or -m switch.

GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 wc used to be part of the GNU textutils package; it is now part of GNU coreutils.

Usage

  • wc -l print the line count
  • wc -c print the byte count
  • wc -m print the character count
  • wc -L print the length of longest line
  • wc -w print the word count

External links

from linux.die.net
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK