wc (Unix)

wc (short for word count) is a command in Unix and Unix-like operating systems.

wc
The wc command
Original author(s)Joe Ossanna
Developer(s)AT&T Bell Laboratories
Initial releaseNovember 3, 1971 (1971-11-03)
Operating systemUnix, Unix-like, V, Plan 9, Inferno, MSX-DOS
TypeCommand

The program reads either standard input or a list of 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  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 and character count. This difference arises with Unicode which includes multi-byte characters. The desired behaviour is selected with the -c or -m options.

History

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.[1] It appeared in Version 1 Unix.[2]

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.[3]

The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project[4] and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[5]

A wc command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.[6]

Usage

  • wc -c <filename> prints the byte count
  • wc -l <filename> prints the line count (note that if the last line does not have \n, it will not be counted)
  • wc -m <filename> prints the character count
  • wc -w <filename> prints the word count
  • wc -L <filename> prints the length of the longest line (GNU extension)
gollark: Also, Python libraries generally seem to be imperative stuff with a thin OOP veneer which makes it slightly more irritating to use.
gollark: ```Internet Protocols and Support webbrowser — Convenient Web-browser controller cgi — Common Gateway Interface support cgitb — Traceback manager for CGI scripts wsgiref — WSGI Utilities and Reference Implementation urllib — URL handling modules urllib.request — Extensible library for opening URLs urllib.response — Response classes used by urllib urllib.parse — Parse URLs into components urllib.error — Exception classes raised by urllib.request urllib.robotparser — Parser for robots.txt http — HTTP modules http.client — HTTP protocol client ftplib — FTP protocol client poplib — POP3 protocol client imaplib — IMAP4 protocol client nntplib — NNTP protocol client smtplib — SMTP protocol client smtpd — SMTP Server telnetlib — Telnet client uuid — UUID objects according to RFC 4122 socketserver — A framework for network servers http.server — HTTP servers http.cookies — HTTP state management http.cookiejar — Cookie handling for HTTP clients xmlrpc — XMLRPC server and client modules xmlrpc.client — XML-RPC client access xmlrpc.server — Basic XML-RPC servers ipaddress — IPv4/IPv6 manipulation library```Why is there, *specifically*, **in the standard library**, a traceback manager for CGI scripts?
gollark: ```Structured Markup Processing Tools html — HyperText Markup Language support html.parser — Simple HTML and XHTML parser html.entities — Definitions of HTML general entities XML Processing Modules xml.etree.ElementTree — The ElementTree XML API xml.dom — The Document Object Model API xml.dom.minidom — Minimal DOM implementation xml.dom.pulldom — Support for building partial DOM trees xml.sax — Support for SAX2 parsers xml.sax.handler — Base classes for SAX handlers xml.sax.saxutils — SAX Utilities xml.sax.xmlreader — Interface for XML parsers xml.parsers.expat — Fast XML parsing using Expat```... why.
gollark: There is no perfect language.
gollark: ```Internet Data Handling email — An email and MIME handling package json — JSON encoder and decoder mailcap — Mailcap file handling mailbox — Manipulate mailboxes in various formats mimetypes — Map filenames to MIME types base64 — Base16, Base32, Base64, Base85 Data Encodings binhex — Encode and decode binhex4 files binascii — Convert between binary and ASCII quopri — Encode and decode MIME quoted-printable data uu — Encode and decode uuencode files```Mostly should be libraries outside of the python core, and why are they not under file formats?

See also

References

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.