标题: 如何用find或findstr在同一行判断多个词是否存在
[打印本页]
作者: tampoco
时间: 2007-9-26 09:45
标题: 如何用find或findstr在同一行判断多个词是否存在
请问如何用find或findstr在文本的同一行判断多个词是否存在?
例如:
判断同一行是否同时存在单词apple和red。
作者: tampoco
时间: 2007-9-26 09:55
或者再把问题衍生下,判断相对某一个词的所在行的下面3行的另一个词是否存在,用find或findstr也能做到吗?
作者: wudixin96
时间: 2007-9-26 09:56
findstr ".*apple.*red.* .*red.*apple.*" hah.txt
???
作者: tampoco
时间: 2007-9-26 10:57
谢谢你的回答!
我的第二个问题可能表述不清,举个例子吧。
例如判断如下情形:
某一行有red,要求判断比red下面三行是否有apple(比如red在第4行,apple在第7行),这能否用find或findstr做到呢?
作者: yoyodos
时间: 2007-9-26 12:23
俺写个程序行不?
setlocal enabledelayedexpansion
cd.>re.txt
for /f "tokens=1* delims=:" %%i in ('findstr /n "red" test.txt') do (
set/a num=%%i
set/a num+=3
)
for /f "tokens=1* delims=:" %%i in ('findstr /n ".*" test.txt') do (
set/a num2=%%i
if !num2!==!num! (
set str=%%j
echo !str!|findstr "apple">>re.txt || echo no apple >>re.txt
)
)
pause
作者: tampoco
时间: 2007-9-27 15:55
谢谢你!你的程序也很好,可以用。学习中。。。