0

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

3
  • 1
    What exactly is the question? Are you asking to have the script written for you?
    – LotPings
    May 26, 2018 at 11:09
  • no, I'm not asking to have the script written for me, but mainly to let me see alternatives. I am pretty new to batch-scripting.. And i have googled my ass of to this for around 20 hours, but can't figure it out. May 27, 2018 at 21:16
  • Since git_commit.log is in.json format use PowerShell for parents count ((Get-Content .\git_commit.log | ConvertFrom-Json).parents).count returns 19 here. Otherwise it's unclear to me where the version number should come from, there is none in the file?
    – LotPings
    May 27, 2018 at 22:20

2 Answers 2

2

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

1
  • 2
    This will not count multiple matches on a line, and catch possibly unwanted variants grandparent or parents This will exclude the variants findstr /i "\<parent\>" commits.txt
    – LotPings
    May 26, 2018 at 12:58
1

We finally figured it out. We used a script in C that a friend of mine made. Was not was i was searching for, but it works. `

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINESZ 1024

int main(int argc, char **argv)
{
    if(argc < 3){
        printf("Usage: count.exe <stack> <needle>\n");
        exit(0);
    }
    char* stack = argv[1];
    char* needle = argv[2];
    int count = 0;
    char buff[LINESZ];
    FILE *fin = fopen (stack, "r");
    if (fin != NULL) {
        while (fgets (buff, LINESZ, fin)) {
            if(strstr(buff,needle)){
                count += 1;
            }
        }
        fclose (fin);
    }
    printf("%d\n",count);
}

It is compiled to https://github.com/godzillamesel/disclovestory/blob/master/scripts/sys/update/count.exe if you are gonna need it. count.exe

3
  • (1) There’s no such thing as “a script in C”.  If it’s compilable, it’s called a program. (2) How is this any better than the findstr answer?  Does this count multiple occurrences on a line?  Does it ignore words like “apparently”, “grandparent” and “parenting”? May 31, 2018 at 5:21
  • i have not tested the count program yet if it ignores the "family" of a word, it is not my need really because it gives me what i need for my update script.grandparent will not appaer.But it counts how many occurrences the word will appear in the "log-file" Jun 1, 2018 at 6:20
  • tested now, it takes the all words with parents in it :/ but as i said, for my use it works good enough. Jun 1, 2018 at 6:22

You must log in to answer this question.

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