1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Batch script that counts how many times a string appears in a file

Discussion in 'Programming' started by Cleptography, Mar 17, 2011.

  1. Cleptography

    Cleptography New Member

    This simple example will count how many times a specified string appears in a file.
    Code:
    @echo off
     setlocal
    
    set str2find=world
    set file=%~1
    set token=0
    
    for /f "tokens=*" %%- in (%file%) do (
        set str=%%-&&call :NEXT
    )
    goto :COUNT
    
    :NEXT
    for /f "tokens=1,*" %%a in ("%str%") do (
        set str=%%b
        set strfind=%%a
    )
    if /i "%strfind%"=="%str2find%" set /a token=%token%+1
    if "%str%"=="" goto :eof
    goto :NEXT
    
    :COUNT
    echo.%str2find% was found %token% times.
     
  2. RITESH KAKKAR

    RITESH KAKKAR New Member

    What the use of it??
     
  3. Cleptography

    Cleptography New Member

    Its pretty self explanatory.
    Don't troll me because you have nothing better to do.
     
  4. RITESH KAKKAR

    RITESH KAKKAR New Member

    Hi, friend i have no idea about uP..!!
     
  5. Cleptography

    Cleptography New Member

    You are asking questions about 8085 processors and assembly language and you can't understand what this simple little batch script does.
    Yes you are trolling me in a very childish manner.
     
  6. RITESH KAKKAR

    RITESH KAKKAR New Member

    Please tell what it does?? i am new to computer language.
     

Share This Page