FIND Command

SieSie Member Posts: 1,195

**** the lines containing the string into the text file. Easy enough.

It also **** all of the names and file paths of all the other files it scans into the text file. Even if it does not find the string.

I want to search for a string within 15 files and only **** the file names and the string line into the text file.

Foolproof systems don't take into account the ingenuity of fools


  • wastedtimewastedtime Member Posts: 586 ■■■■□□□□□□
    This isn't the exact format but this should get you started.
    for /F "tokens=5" %i in ('dir') do echo %i

    Note %i could be a referance like :MyFunc

    My bad didn't mean to pipe dir to for.
  • sprkymrksprkymrk Member Posts: 4,884 ■■■□□□□□□□
    I tried this and it works - use another command first (findstr), and then use that to create a list of files that contain the string. Then run your find command using that file as your list of files to search. You can do it all on a single command line like this:
    findstr /I /M "vista" c:\temp\*.txt >> c:\temp\findlog.log && for /f %F in (
    C:\temp\findlog.log) do find /N /I "vista" %F >> c:\temp\results.log

    Note there may be some line wrapping, but it should all be entered without a carriage return. Obviously substitute the string and original files to search per your needs.

    In the example, I am searching for the word/string "vista" in all my text files under C:\temp. Using the /M switch in findstr tells it to only print the names of file names that match, not the actual line and string. This output is sent to the file c:\temp\findlog.log (named .log to be excluded from future *.txt searches, you can handle this in whatever way you want). Then the ampersand symbols (&&) say that if the first command run is successful, now run the "for" command, which says that for every file listed in findlog.log, search for the string "vista" and send the filename, line number and string to the c:\temp\results.log file.

    HTH :)

    If you want to save the above command line as a batch file, use 2 percent symbols instead of one in the "for" command, like so:

    for /f %%F in (C:\temp\findlog.log) do find /N /I "vista" %%F >> c:\temp\results.log
    All things are possible, only believe.
  • SieSie Member Posts: 1,195
    Thank you very much for this Mark, I'll test it tonight. (though im sure it will work!)

    (Sorry for delay been away for a few days just back into work today, doesnt time off fly?? icon_lol.gif )

    Cheers again!!
    Foolproof systems don't take into account the ingenuity of fools
Sign In or Register to comment.