OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to find if a file contains a given string using Windows command line

  • Thread starter Thread starter Jai
  • Start date Start date
J

Jai

Guest
I am trying to create a batch (.bat) file for windows XP to do the following:

Code:
If (file.txt contains the string 'searchString') then (ECHO found it!) 
ELSE(ECHO not found)

So far, I have found a way to search for strings inside a file using the FIND command which returns the line in the file where it finds the string, but am unable to do a conditional check on it.

For example, this doesn't work.

Code:
IF FIND "searchString" file.txt ECHO found it!

Nor does this:

Code:
IF FIND "searchString" file.txt=='' ECHO not found

Any Ideas on how this can be done?
<p>I am trying to create a batch (.bat) file for windows XP to do the following:</p>

<pre><code>If (file.txt contains the string 'searchString') then (ECHO found it!)
ELSE(ECHO not found)
</code></pre>

<p>So far, I have found a way to search for strings inside a file using the <strong>FIND</strong> command which returns the line in the file where it finds the string, but am unable to do a conditional check on it.</p>

<p>For example, this doesn't work.</p>

<pre><code>IF FIND "searchString" file.txt ECHO found it!
</code></pre>

<p>Nor does this:</p>

<pre><code>IF FIND "searchString" file.txt=='' ECHO not found
</code></pre>

<p>Any Ideas on how this can be done?</p>
Continue reading...
 

Latest posts

M
Replies
0
Views
1
MusicLovingIndianGirl
M
Q
Replies
0
Views
2
quora question
Q
Top