Help needed in Text file


  1. Posts : 36
    windows7 64 bit
       #1

    Help needed in Text file


    Hi, I have a folder which has 20 text files and i need to find a word "Core" on the text files and and need to list out the file name where the text "Core" exists.

    Code:
    for /R %%a in (C:\Sample\*.txt) do find "%Core" %%a >> output.txt
    But the above code is not working as expected. any sample code to achieve this please
      My Computer


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    Hello Born2achieve (remember me? :)),

    Do these command line snippets help you achieve your goal?

    Code:
    for %A in ( C:\Sample\*.txt ) do find "Core" "%~A" && echo %~fA>> output.txt

    Below is the same but recurses the search into sub-folders, starting at C:\Sample,

    Code:
    for /r "C:\Sample" %A in ( *.txt ) do find "Core" "%~A" && echo %~fA>> output.txt
    Last edited by Pyprohly; 15 Feb 2015 at 01:16. Reason: Corrected grammar.
      My Computer


  3. Posts : 36
    windows7 64 bit
    Thread Starter
       #3

    Hi Phyroply,

    Thakns for your reply and sorry it's not working for me. Below is the output,

    Code:
    C:\Sample>search.bat
    The following usage of the path operator in batch-parameter
    substitution is invalid: %~A" && echo %~fA>> output.txt
    
    For valid formats type CALL /? or FOR /?
    search.bat was unexpected at this time.
    Any suggestions or corrections
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    Double up the percent symbols when running the commands in batch files. E.g. "%A" should become "%%A".
      My Computer


  5. Posts : 36
    windows7 64 bit
    Thread Starter
       #5

    sorry, still it doesn't finds the keyword.

    This is my code

    Code:
    for /R %%A in (C:\Sample\*.txt) do find "core" "%%~A" && echo %%~fA>> output.txt
    any suggestion please
      My Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #6

    Your script snippet's syntax is incorrect. Use one of the two lines I've suggested above.
      My Computer


  7. Posts : 36
    windows7 64 bit
    Thread Starter
       #7

    Sorry my bad, you script is perfect. worked like charm.

    thank you so much for your time on this
      My Computer


  8. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #8

    Always welcome
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:08.
Find Us