标题: 怎么同时在一个文件中搜索两个不同的字符串
[打印本页]
作者: a9319751
时间: 2007-1-26 05:48
标题: 怎么同时在一个文件中搜索两个不同的字符串
怎么同时在一个命令中搜索两个不同的字符串,然后来执行不同的命令.
type 1.txt |find 1 command1 |find 2 command2
?
[
Last edited by a9319751 on 2007-1-26 at 06:31 AM ]
作者: qzwqzw
时间: 2007-1-26 07:29
看两个字符串是什么关系
查找同时包含两个字符串的行
findstr /c "str1" | findstr /c "str2"
查找包含其中一个字符串的行
findstr "str1 str2"
作者: a9319751
时间: 2007-1-26 08:00
比如 dir c:发现1.exe则执行1.exe 发现2.exe则执行2.exe,
作者: qzwqzw
时间: 2007-1-26 08:19
这实际上可以看成两个独立的查找
用两句find就可以了
dir c: /b | find "1.exe" && c:1.exe
dir c: /b | find "2.exe" && c:2.exe
作者: a9319751
时间: 2007-1-26 08:27
但是我不想用两个DIR,我想一个DIR,就有两个查找,怎么能不更多的执行dir命令呢?
作者: qzwqzw
时间: 2007-1-26 09:57
方法一:
dir c: /b > out.txt
find "1.exe" out.txt >nul && call c:1.exe
find "2.exe" out.txt >nul && call c:2.exe
方法二:
dir c: /b | findstr /c:"1.exe" /c:"2.exe" >out.txt
find "1.exe" out.txt >nul && call c:1.exe
find "2.exe" out.txt >nul && call c:2.exe
另外,请尽量一次把问题描述清楚
作者: a9319751
时间: 2007-1-26 10:52
谢谢
如果我不想使用临时文件呢?