in reply to Count word in my dir
I am having a bit of trouble understanding what exactly you are trying to accomplish... but I'll try to help you anyway.
There is are more ways to do this than you can shake a stick at (why you would go around shaking sticks at things I have no idea..) but I will propose a couple here.
$ ls | grep FOO | wc -l
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my $path="/some/where/over/the/rainbow"; opendir(DIR,$path) or die "$!"; my @list=readdir(DIR); closedir(DIR); my @collect=grep /FOO/,@list; my $count = $#collect + 1; printf "total count = %d\n",$count;
Ahh... here is a better problem, one with a pair of fine solutions!
$ grep FOO * | wc -l
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my $path="/some/where/over/the/rainbow"; open (DIR,$path) or die "$!"; my @file_list=readdir(DIR); closedir(DIR); my $count = 0; foreach my $file(@file_list){ open(FIN,"< $file") or die "$file: $!"; my @slurp=<FIN>; close(FIN); my @collect=grep /FOO/,@slurp; $count += ($#collect + 1); } printf "My total count was: %d\n",$count;
A couple of things I should point out:
Hope this helps.
Peter @ Berghold . Net
Sieze the cow! Bite the day!
Test the code? We don't need to test no stinkin' code! All code posted here is as is where is unless otherwise stated.
Brewer of Belgian style Ales
|
|---|