Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > W

wc(1)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

wc — count words, lines, and bytes or characters in a file

SYNOPSIS

wc [-c|-m] [-lw] [file]...

DESCRIPTION

The wc command counts lines, words, and bytes or characters in the named files, or in the standard input if no file names are specified. It also keeps a total count for all named files.

A word is a string of characters delimited by spaces, tabs, or newlines.

Options

wc recognizes the following options:

-c

Report the number of bytes in each input file.

-l

Report the number of newline characters in each input file.

-m

Report the number of characters in each input file.

-w

Report the number of words in each input file.

The c and m options are mutually exclusive. Otherwise, the l, w, and c or m options can be used in any combination to specify that a subset of lines, words, and bytes or characters are to be reported.

When any option is specified, wc reports only the information requested. If no option is specified, the default output is -lwc.

When a file is specified on the command line, its name is printed along with the counts.

Standard Output

By default, the standard output contains an entry for each input file in the form:

newlines words bytes file

If the -m option is specified, the number of characters replaces the bytes field in this format.

If any option is specified, the fields for the unspecified options are omitted.

If no file operand is specified, neither the file name nor the preceding blank character is written.

If more than one file operand is specified, an additional line is written at the end of the output, of the same format as the other lines, except that the word total (in the POSIX locale) is written instead of a file name and the total of each column is written as appropriate.

Under UNIX Standard environment, a word is a string of characters delimited by spaces, tabs, newline, carriage-return, vertical tab, or form-feed.

RETURN VALUE

wc exits with one of the following values:

0

Successful completion.

>0

An error occurred.

EXTERNAL INFLUENCES

For information about the UNIX Standard environment, see standards(5).

Environment Variables

LC_CTYPE determines the range of graphics and space characters, and the interpretation of text as single- and/or multibyte characters.

LC_MESSAGES determines the language in which messages are displayed.

If LC_CTYPE or LC_MESSAGES is not specified in the environment or is null, they default to the value of LANG.

If LANG is not specified or is null, it defaults to C (see lang(5)).

If any internationalization variable contains an invalid setting, they all default to C. See environ(5).

International Code Set Support

Single- and multibyte character code sets are supported. with a newline character, the count will be off by one.

WARNINGS

The wc command counts the number of newlines to determine the line count. If a text file has a final line that is not terminated with a newline character, the count will be off by one.

EXAMPLES

Print the number of words and characters in file1:

wc -wm file1

The following is printed when the above command is executed:

words chars file1

where words is the number of words and chars is the number of characters in file1.

SEE ALSO

standards(5).

STANDARDS CONFORMANCE

wc: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.