Windows – Word counter — Batch

batchopen sourcepowershellscriptwindows

I want to make a batch-script that counts the times that the word "parent" appear in the file,

http://api.github.com/repos/godzillamesel/disclovestory/commits

I'm currenly downloading this file with:

cd "$env:programfiles\DiscLovestory\sys\update" 
Remove-Item "git_commit.log" 
[Net.ServicePointManager]::SecurityProtocol =  tls12, tls11, tls" 
wget -O git_commit.log http://api.github.com/repos/godzillamesel/disclovestory/commits 
pause

Having this is file is also gonna be needed as a "update-note" to the user. This script went straight to powershell, since i don't know how bitsadmin works, but if you also know how that should work, be my guest to help me out! As my script is based to be a batch-only script.

I want the output to go to: "%programfiles%\DiscLovestory\sys\update\version.log" and also in registry:

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DiscLovestory" /v DisplayVersion /t REG_SZ /d

In both output places it should be enough to just put version as follow: "x.xx" without quotations.

And if you wanna follow up on the script, or use it, be my guest. It is open-source at: https://github.com/godzillamesel/disclovestory

Best Answer

You may try this:

@echo off
set /a COUNT=0
for /f %%i in ('findstr /i /c:"parent" commits.txt') do (
  set /a COUNT=COUNT + 1
)
echo "parent" words count: %COUNT% 
pause

Referrence:how to get the word count within batch file in MS DOS and manipulate to exit loop

Related Question