Computer Hope
Microsoft => Microsoft DOS => Topic started by: kamak on May 16, 2008, 05:28:06 AM
-
Hi all, how would i go about making a batch file that reads a text file, and if the text file contains a certain word, execute a certain action?
Eg. i want my batch file to check if text file EXAMPLE.txt has EXAMPLEWORD in it, and if it does i want the batch file to continue with the code, or not do anything if EXAMPLEWORD is not found.
Thanks in advance,
Kamak
-
for /f "tokens=* delims=" %%v in ('type example.txt ^| find "EXAMPLEWORD"') do echo %%v
This example executes the echo instruction if the argument is found. You can change this to whatever instruction you want executed. The search for EXAMPLEWORD is case sensitive. Add the /i switch to the find command to make it case insensitive.
Happy coding, 8)
-
I am sure findstr takes in a file as input
findstr /I /G:file "STRING to SEARCH" && execute_command
-
Findstr takes a file or receives an input via a pipe as Sidewinder's example shows.
-
Findstr takes a file or receives an input via a pipe as Sidewinder's example shows.
yup, so using type would be unnecessary , not that its a big deal anyway :)
-
I am sure findstr takes in a file as input
findstr /I /G:file "STRING to SEARCH" && execute_command
findstr /I "String to search" filename.txt>nul && execute_command
-
Thanks all, you've been really helpful :)