Announcement

Collapse
No announcement yet.

DOS Batch to Find String in All Files

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • DOS Batch to Find String in All Files

    Hi,
    I'm struggling with the correct DOS Batch commands (XP and W7) to find a specific character "@" in any and all text files in one directory and to count those occurences. Here's what I've got, but still returning 0 count. If I put a specific file name in the FOR command, it WILL count any "@" that it finds. But doesn't seem to work with "." or "*.*) in the fileset parm which should cause the FOR command to read thru ALL files. I'm trying to display the found tokens with the %%G but that doesn't work. Not necessary, just for debugging. Any help is very appreciated.

    Code:
    REM Find and count all files with email addresses
    REM Assume any user_data record with @ is valid email address
    FOR /F "delims=@ eol=`" %%G IN (.) DO (CALL :CHECK %%G)
    echo (
    echo Number of Emails Sent = %count%
    echo (
    GOTO :eof
     
    :CHECK %%G
    set _DataIn=%%G
    echo CHECK %_DataIn%
    set /a count+=1
    GOTO :eof
    Last edited by Rems; 16th August 2012, 16:32. Reason: added [CODE] tags

  • #2
    Re: DOS Batch to Find String in All Files

    I think I've found it:

    Code:
     
    findstr /R /N "@" *.* | find /c ":"

    Comment

    Working...
    X