The wc (Word count) program prints a count of bytes,words,and lines in (presumably) a text file.

Very useful command on linux.

Here is the exmaples:

1. Default output

$wc test.lst
  3746   3746 403618 test.lst

The test.lst file has 3746 lines, 3746 whitespace-delimited words and 403618 bytes.

2. -w option, prints words counts

wc -w test.lst
3746 test.lst

3. -c option, prints byte counts

wc -c test.lst
403618 test.lst

4. -l option, prints line counts

wc -l test.lst
3746 test.lst

5. -L Locate the longest line in the file and print its length in bytes

wc -L test.lst
115 test.lst

6. prints result from stand input

$wc -
I love dog      0       3      10 -

In the example above, type "I love dog" to standard input.

It is equivalent to the following result

echo -n "I love dog"| wc
0       3      10

Note: -n option is important in the above case.

Comments powered by CComment