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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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)
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

findstr "<DOCNO>" *.xml | find /c "<DOCNO>"

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.