Print line if contains word

后端 未结 2 1717
再見小時候
再見小時候 2021-01-26 17:07

I am trying to make a batch file to execute a few things for me.
Now I do understand a few programming languages, but I haven\'t done much in batch file programming yet.

2条回答
  •  春和景丽
    2021-01-26 17:52

    If you simply want to output the matching line with no logic checking, do

    findstr /i "node" "%file1%"
    

    If you want to execute some code if the line is found, use conditional execution.

    findstr /i "node" "%file1%" && (
    
        rem File contained "node".  Do some stuff.
    
    ) || (
    
        rem File did not contain "node".  Do something else.
    
    )
    

    And if you want to use findstr to test for the existence of a string without actually dumping the result to the console, simply add >NUL either before or after the findstr command.

    >NUL findstr /i "node" "%file1%" && (success) || fail
    

提交回复
热议问题