Search File content in a folder for a keyword

I have a folder with several XML files ( around 700 files) . Is there a quick way to know how many times a specific word is used in the content of the whole set of files

For example, I am looking for a word <DOCNO>  .  I need to know in the content of all 700 files , how many times this word appear
I am not sure windows file search wiith content can do this . Also I need a realiable result  
( I am looking for a solution that cost nothing  )
Sam OZAsked:
Who is Participating?
findstr "<DOCNO>" *.xml | find /c "<DOCNO>"

Open in new window

Try the following command line:
findstr "<DOCNO>" *.xml

Open in new window

slightwv (䄆 Netminder) Commented:
I don't thing findstr will retrn the count.

Try this:
find /C "<DOCNO>" *.xml

If that doesn't get you what you want or you need more, I would look at a Powershell solution.

Let us know the requirements and we can try and help.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Sam OZAuthor Commented:
Both above solutions are not giving what I want .  The requirement is - Do the content search and Get the total count of <DOCNO>
If the word <DOCNO> is present 20,000 times in the 700 xml files , the result should give just the value 20,000
( I need to get this count and then match it with a database row count  for the number of Documents. In the XML file for each docuemnt, I will have <DOCNO> . So it gives me the total count of documents)
slightwv (䄆 Netminder) Commented:
The above command should work but probably isn't that fast.

I would look at Powershell.  You can even likely extend the Powershell script to actually connect to the database and do the validation.

To get the doc count you want in Powershell try this:
$(get-content *.xml | select-string -pattern "<DOCNO>").count

Open in new window

Sam OZAuthor Commented:
@ zc2 . Thanks . It works . Can you please give me an enhancement of writing it to a text file
Preferably If I can get a batch script for multiple folders , it is great
 CD to  Folder1 and get count  and write to F:\DocCount\Folder1.txt
 CD to Folder2 and get count and write to   F:\DocCount\Folder2.txt
  ........  may have more folders .

@slightwv   ...  How to get powershell to a Windows 2012 server ?
slightwv (䄆 Netminder) Commented:
Powershell comes with Windows:

>>me an enhancement of writing it to a text file
simple redirect will work
--make sure on on the X: drive then:

cd X:\Folder1
findstr "<DOCNO>" *.xml | find /c "<DOCNO>" > F:\DocCount\Folder1.txt
cd X:\Folder2
findstr "<DOCNO>" *.xml | find /c "<DOCNO>" > F:\DocCount\Folder2.txt

Open in new window

The following batch should recursively traverse sub folders and creates a file for each with the count
@echo OFF
set CDp=%CD:~2%
call :calc . %CDp:\=%.txt
setlocal enabledelayedexpansion
for /D /R %%D in (*) do (
    set dp=%%~pnD
    call :calc %%D !dp:\=!.txt
exit /b

findstr ""<DOCNO>" "%1\*.xml" | find /c ""<DOCNO>" >%2
exit /b

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.