|
|
| David Sagenaut 2006-02-20, 8:49 pm |
| If I have a file like this:
xxxxxx xxxxxx test xxxxx
test xxxxx test xxxxxxxxx
xxxxxx test xxxxxxxxxxx
how can I count the word "test"? Thanks!
Alex
| |
| Janis Papanagnou 2006-02-20, 8:49 pm |
| David Sagenaut wrote:
> If I have a file like this:
>
> xxxxxx xxxxxx test xxxxx
> test xxxxx test xxxxxxxxx
> xxxxxx test xxxxxxxxxxx
>
> how can I count the word "test"? Thanks!
>
> Alex
>
>
One possibility...
tr ' ' '\n' | grep -c test
Janis
| |
| Ed Morton 2006-02-20, 8:49 pm |
| David Sagenaut wrote:
> If I have a file like this:
>
> xxxxxx xxxxxx test xxxxx
> test xxxxx test xxxxxxxxx
> xxxxxx test xxxxxxxxxxx
>
> how can I count the word "test"? Thanks!
>
> Alex
>
>
What do mean by "word"? If you had:
abc testosterone def
would you count that? What about :
this is a test.
or does "test" need to be surrounded by white-space?
This will do what you want if you just want to count ocurrences of the
string "test"
gawk -v RS="test" 'END{print (NR?NR-1:0)}' file
Regards,
Ed.
| |
| Xicheng 2006-02-21, 2:49 am |
| David Sagenaut wrote:
> If I have a file like this:
>
> xxxxxx xxxxxx test xxxxx
> test xxxxx test xxxxxxxxx
> xxxxxx test xxxxxxxxxxx
>
> how can I count the word "test"? Thanks!
perl -lne '$n += () = /test/g }{ print $n' myfile
Xicheng
|
|
|
|