2

I already could manage to count strings in all files in directory:

grep -roh „XXX" . | wc –w

But I don't know how to isolate the statement. I only want to count the words in files which have the the following string "2015-09-25" in the filename.

Can anybody help me here?

2 Answers 2

1

This should work, it uses find to isolate the files that you are interested in and then runs grep just on those files:

find /mydir -maxdepth 1 -type f -name "*2015-09-25*" -execdir grep -roh "XXX" "{}" \+ | wc -w

If you want to find files in subdirectories of /mydir as well, just remove -maxdepth 1

1

If all files are on current directory, try

grep -oh "XXX" *2015-09-25* 

else try

 grep -roh -c --include="*2015-09-25*" "XXX" 

where

  • -r tell grep to recurse
  • --include="*2015-09-25*" filter on file's basename.
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .