How to count words,letters,lines in a file

Give the name of a file as an argument; if none is given, wc works on standard input. By default, wc outputs three columns, displaying the counts for lines, words, and characters in the text.

To output the number of lines, words, and characters in file `outline', type:

$ wc outline RET

The following subsections describe how to specify just one kind of count with wc, and how to count text in Emacs.

Count Characters

Use wc with the `−c' option to specify that just the number of characters be counted and output. · To output the number of characters in file `classified.ad', type:

$ wc −c classified.ad RET

Counting words

Use wc with the `−w' option to specify that just the number of words be counted and output. To output the number of words in the file `story', type:

$ wc −w story RET

To output counts for several files, first concatenate the files with cat, and then pipe the output to wc. To output the combined number of words for all the files with a `.txt' file name extension in the current directory, type:

$ cat *.txt | wc −w RET

Counting lines


Use wc with the `−l' option to specify that just the number of lines be counted and output.To output the number of lines in the file `outline', type:

$ wc −l outline RET

Posted on: 16/12/2009








0 Comments
If you want to leave a comment please Login or Register