Re: tell me how many specific words there are in the file?
- From: Logan Shaw <lshaw-usenet@xxxxxxxxxxxxx>
- Date: Sat, 18 Mar 2006 21:28:55 GMT
Måns Rullgård wrote:
Pascal Bourguignon <usenet@xxxxxxxxxxxxxxxxx> writes:
nitrogenix.fusion@xxxxxxxxx writes:
I'm trying to get the user to enter a word, then the script shouldman grep
search for how many of that word exists in the file. For example, I
want it to say, "There are 7 'and' words in the file", or "There are 5
'the' words in the file" etc...
I have the following which I used to find a specific character, but I
need to change this round to find words instead.
tr -dc $char < text | wc -c
Thanks for your help.
man 7 regex
Off the top of my head, I can't think of a grep command that will
count multiple matches on the same line. Am I overlooking something?
Nope, I think you're right. But there is an easiy enough solution:
fmt -1 "$file" | grep -cw "$word"
I know, it's a dirty solution, but it works. Assuming that "fmt" and
you agree on what makes a word boundary.
- Logan
.
- References:
- tell me how many specific words there are in the file?
- From: nitrogenix . fusion
- Re: tell me how many specific words there are in the file?
- From: Pascal Bourguignon
- Re: tell me how many specific words there are in the file?
- From: Måns Rullgård
- tell me how many specific words there are in the file?
- Prev by Date: Re: LFS and stdio
- Next by Date: Re: what's writing to my hard disks?
- Previous by thread: Re: tell me how many specific words there are in the file?
- Next by thread: Re: tell me how many specific words there are in the file?
- Index(es):