0

バッチ ファイルを使用して、特定のテキスト (文字列のグループ) がファイルに存在するかどうかを検索しています。ここに私が書いたものがありますが、テキストでは機能しません。文字列に対して機能するだけです(テキストを検索するのではありません)。

rem %1 is name of the file whose text is being found
FindStr /C:%2 %1 
If %ERRORLEVEL% EQU 0 echo text %2 is Present
If %ERRORLEVEL% EQU 1 echo text %2 is not Present

たとえば、「I have breakfast」というテキストを検索して、「I have breakfast every day」を含むファイルを検索する必要がある場合、コマンド echo は、「 text I have breakfast is present 」と出力する必要があります。

どんな助けでも!お願いします。

4

3 に答える 3

0

スクリプトを呼び出すと、これは機能するはずですscript.bat "file name" "search string"

@echo off&setlocal
rem %1 is name of the file whose text is being found
FindStr /C:"%~2" "%~1" >nul
If %ERRORLEVEL% EQU 0 echo text %2 is Present
If %ERRORLEVEL% EQU 1 echo text %2 is not Present
于 2013-04-07T13:23:51.630 に答える
0

次のことができます。

FindStr /C:"%~2" "%~1" >nul && echo text "I have breakfast is present".
于 2013-04-08T14:29:39.793 に答える