Live Chat!

word count

          0 votos

September 17th, 2006 mysurface Posted in Common, cat, echo, wc | Hits: 7183 |

Word count is a very common tools that used to calculate number of lines, words and characters. For example if I can do this

echo "hello world." | wc
1       2      13

The result indicate that there are 1 line, 2 words and 13 characters.

You can output result separately, -c indicates characters, -w indicate words, -l indicate lines.

echo "hello world." | wc -c

You can count for any file even binaries by using -c

cat hello.c | wc -c

Try to check with ls -l hello.c, you will discover that, the characters count is actualy same as the bytes of the files.

Therefore,

cat `which cat` | wc -c

is actually returns file size of cat binaries in terms of number of bytes.

One Response to “word count”

  1. Another good use of wc is to see the number of files of a specific type available in a directory.

    ls *. | wc -l

    Another use is to find files of a specific type in an entire folder (including its sub-dirs)

    find ./ -name “*.” | wc -l

Leave a Reply