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

    Joined:
    Sep 2, 2010
    Messages:
    39
    Likes Received:
    7
    Trophy Points:
    0
    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

    Joined:
    Mar 16, 2011
    Messages:
    16
    Likes Received:
    1
    Trophy Points:
    3
    What the use of it??
     
  3. Cleptography

    Cleptography New Member

    Joined:
    Sep 2, 2010
    Messages:
    39
    Likes Received:
    7
    Trophy Points:
    0
    Its pretty self explanatory.
    Don't troll me because you have nothing better to do.
     
  4. RITESH KAKKAR

    RITESH KAKKAR New Member

    Joined:
    Mar 16, 2011
    Messages:
    16
    Likes Received:
    1
    Trophy Points:
    3
    Hi, friend i have no idea about uP..!!
     
  5. Cleptography

    Cleptography New Member

    Joined:
    Sep 2, 2010
    Messages:
    39
    Likes Received:
    7
    Trophy Points:
    0
    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

    Joined:
    Mar 16, 2011
    Messages:
    16
    Likes Received:
    1
    Trophy Points:
    3
    Please tell what it does?? i am new to computer language.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice