Search code examples
cmdfindstr

Getting string from cmd output


I am running a command that produces the following output -

                           Processing/
2019-02-07 12:10:43        305 Test1.csv
2019-02-07 12:11:43        306 Test2.csv

How can I use findstr to extract the file name. For example, Test1.csv and Test2.csv


Solution

  • You don't need to use findstr. You may use:

    @echo off
    
    for /F "tokens=4" %%A IN ('command') do (
        echo %%A
    )
    

    to echo the string you want.

    If you don't want to echo them, do them whatever you want: assign them to a variable, e.t.c., but remember that they are assigned in the for loop variable %%A.