Re: tell me how many specific words there are in the file?



Pascal Bourguignon <usenet@xxxxxxxxxxxxxxxxx> writes:

nitrogenix.fusion@xxxxxxxxx writes:

Hi,

I'm trying to get the user to enter a word, then the script should
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 grep
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?

--
Måns Rullgård
mru@xxxxxxxxxxxxx
.



Relevant Pages

  • Re: tell me how many specific words there are in the file?
    ... I'm trying to get the user to enter a word, then the script should ... Off the top of my head, I can't think of a grep command that will ... Am I overlooking something? ... COMPONENT EQUIVALENCY NOTICE: The subatomic particles (electrons, ...
    (comp.unix.programmer)
  • Problem using grep through the unix shell: doesnt accept a regular expression in filename
    ... I'm using the following simple grep command through a .sh shell ... grep "mypattern" < $1 ... However it works perfectly when i execute it on the command prompt by ... replacing $1 by *.txt for example, but when I call the script using ...
    (comp.unix.shell)
  • Re: Q: How to use boolean values and return codes in shell scripts?
    ... On Sat, 20 Sep 2003 at 04:19 GMT, Bernard wrote: ... > I would like to learn how to use boolean values in a script. ... > One example is the return value of a grep command as follows which ...
    (comp.os.linux.misc)
  • Re: Grep Question
    ... In any case you think any char is making a diference in grep command, ... the string into double quotes, ... Please respond to IBM AIX Discussion List ... this...my script does not create file even after redirecting...can some ...
    (AIX-L)