使用批处理文件在.txt文件中搜索单词

时间:2022-03-18 02:22:44

I am looking for a batch file to search through a txt file and if it finds the word "Failed" then EXIT 1. Any help??

我正在寻找一个批处理文件来搜索txt文件,如果它找到单词“Failed”,那么退出1.任何帮助?

3 个解决方案

#1


here is something similar to what Garrett said, but you can run it as a background process while for instance displaying some other info on stdout:

这里有类似于Garrett所说的内容,但您可以将其作为后台进程运行,例如在stdout上显示其他一些信息:

@echo off
@start /wait FIND /C /I "SearchPhrase" path-to-your-file\filename.abc
IF ERRORLEVEL 1 (do-something)

#2


This might get you started...

这可能会让你开始......

type file.txt | find "Failed"

If that returns anything, you set the ERRORLEVEL variable to 1.

如果返回任何内容,则将ERRORLEVEL变量设置为1。

Hope that helps dude!

希望有帮助的家伙!

#3


FindStr "Failed" YourFile.Txt >Nul:
If ErrorLevel 1  
  ... then it is NOT found (findstr returns 0 if found

#1


here is something similar to what Garrett said, but you can run it as a background process while for instance displaying some other info on stdout:

这里有类似于Garrett所说的内容,但您可以将其作为后台进程运行,例如在stdout上显示其他一些信息:

@echo off
@start /wait FIND /C /I "SearchPhrase" path-to-your-file\filename.abc
IF ERRORLEVEL 1 (do-something)

#2


This might get you started...

这可能会让你开始......

type file.txt | find "Failed"

If that returns anything, you set the ERRORLEVEL variable to 1.

如果返回任何内容,则将ERRORLEVEL变量设置为1。

Hope that helps dude!

希望有帮助的家伙!

#3


FindStr "Failed" YourFile.Txt >Nul:
If ErrorLevel 1  
  ... then it is NOT found (findstr returns 0 if found