1.

Solve : Batch file to check the contents in a file?

Answer»

I would like to find a particular word in a text file and check if the word is available in the other text file
C:\>findstr /n /o particular *.txt

textfileone.txt:1:0:particular word

textfiletwo.txt:1:0:particular word

C:\>TYPE textfileone.txt
particular word
C:\>C:\>type findstring.bat
Code: [SELECT]@echo off

Rem Use COMMAND line argument to search for any word

findstr /n /o %1 *.txtC:\>findstring.bat particular
textfileone.txt:1:0:particular word

textfiletwo.txt:1:0:particular word
C:\>REM From the root directory, search the complete disk for the word. In this case the word is "support" The /s option will search all sub directories
The wc -l counts how many times "support" occurred on the disk in a *.txt ( text ) file. Correction: It is only counted one TIME for each file when using the /m option

Code: [Select]findstr /s /m support *.txt | wc -l

517Hey, thanks for the update...

Can you help me to put this in a if condition ....

I have a batch file batch1.bat and two text files first.txt and second.txt file

Batch1.bat should have if statement to check if a particular word is there in first.txt, if available SEND "Success" to second.txt file

Thanks in advanceSureShred,

C:\>type Batch1.bat
Code: [Select]@echo off

REM Use Batch1.bat particular

echo. > second.txt
type second.txt

echo %1 > first.txt

findstr particular first.txt

if %errorlevel%==0 echo Success > second.txt

type second.txt
Output:

C:\>Batch1.bat bad


C:\>Batch1.bat particular

particular
Success
C:\>it works.

Thanks a lot billrich



Discussion

No Comment Found