|
Answer» 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,
KamakCode: [Select]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, I am sure findstr takes in a file as input Code: [Select]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. Quote from: Dias de VERANO on May 16, 2008, 09:35:26 AM 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 Quote from: ghostdog74 on May 16, 2008, 09:14:21 AMI am sure findstr takes in a file as input Code: [Select]findstr /I /G:file "STRING to SEARCH" && execute_command
findstr /I "String to search" filename.txt>nul && execute_commandThanks all, you've been really helpful
|