[SLL] grep and wc help needed

Adam Monsen haircut at gmail.com
Sun Feb 22 06:45:26 PST 2009


> You can count the words by leaving the spaces in, with 'wc -w':
>
> $ cat testfile.txt | tr -d "[:punct:]0-9" | wc -w
> 9

I think the "tr -d ..." might not be necessary in the case where
you're counting words. At least, on my system, wc appears to deal with
punctuation properly.

$ cat test.txt
Hi there. How the-heck are you?

$ wc -w test.txt
6 test.txt


More information about the linux-list mailing list