Search code examples
windowsbatch-filecmdfindstr

how to apply findstr expressions to the first column of a string in a .csv file while returning the entire string in CMD?


I made a btach script and which works well, with the exception of returning additional strings that are not exact matches to the source file.

When i run the script below, it will return additional strings that share the same number structure as the the numbers in the .txt file, but with additional numbers at the end of them ex.

searching for "^%%L" which = "^12210" will return strings for 12210 and 122100,122101,122102 ect..

Any help is greatly appreciated!

batch script:

for /d %%a in (*) do (
    for /f %%f in ("%%a"\*.txt) do (
        for /f %%L in (%%f) do (
            findstr "^%%L" C:path\file.csv  >> %%a.csv
        ) 
    )
    move %%a.csv "%%a" >nul
)

Solution

  • @Compo- Thanks for the assist!! Your comments got me going in the right direction and the problem is solved. I ended up having to modify the expression a bit to return the entire string. Here is what worked.

    findstr "^%%L,*,*\>" C:\path\file.csv.