LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Need help in word count command (https://www.linuxquestions.org/questions/linux-general-1/need-help-in-word-count-command-713054/)

grunge_1 03-20-2009 03:24 AM

Need help in word count command
 
Hi,
I have a file(text.txt) and it something like this:

Book and Book book
I don't know
what to write here Book
I need to know what
Book

Ok, when do word count it should say the word 'book' appear 5 times. I try this command but no luck...!!

grep -i book text.txt |wc -w <--- result 10

cat text.txt | grep -i book |wc -w <--- result 10

cat text.txt | grep -i book |wc -l <--- result 3

grep -c book text.txt <--- result 1


Anyone can help?

Thanks.

acid_kewpie 03-20-2009 03:29 AM

1 - number of words in all the lines which contain the word "book"

2 - same as 1

3 - number of lines containing the word "book"

4 - number of lines containing the word "book", case sensitive.

Maligree 03-20-2009 03:35 AM

Code:

grep -o book <file> | wc -l
Maybe there's a nicer way.

syg00 03-20-2009 03:36 AM

Or perhaps more simply "grep -oi book file | wc -l"

grunge_1 03-20-2009 04:01 AM

Thanks all..
"grep -oi book file | wc -l" working just great!!!


All times are GMT -5. The time now is 12:27 PM.