同时批量搜索多个字符串

时间:2015-03-21 07:58:42

标签: multithreading batch-file findstr

我有这个庞大的设备数据库:

Equipment500
Equipment501
..........
Equipment998
Equipment999

还有一个更大的数据库,其中包含有关设备的详细信息:

Equipment1:details....
Equipment2:details....
..................
Equipment9998:details....
Equipment9999:details....

我需要的是仅选择我需要的设备的详细信息:

for /f "tokens=* delims= " %%a in (%cd%\equipment.db) do (
findstr /i /c:"%%a" details.db > Output\%%a
)

输出当然是一个包含文件的文件夹:

In Equipment500 it will be Equipment500:details....
In Equipment501 it will be Equipment501:details....
..................
In Equipment998 it will be Equipment998:details....
In Equipment999 it will be Equipment999:details....

问题在于需要花费很多时间。

我需要这个多线程,以便它能够在同一时间运行更多的findstr(最好是全部500个)实例,以便立即进行处理。


任何想法都表示赞赏。谢谢!

2 个答案:

答案 0 :(得分:1)

@echo off
echo building input files (this needs some time):
del *.db
for /l %%i in (500,1,999) do @echo Equipment%%i>>equipment.db
for /l %%i in (1,1,9999) do @echo Equipment%%i:Detailswhatever>>details.db

echo %time% start adapting
REM adapt equipment.db:
(for /f "delims=" %%i in (equipment.db) do echo %%i:)>equip.db

REM find all strings:
echo %time% start searching
findstr /g:equip.db details.db >output.txt
echo %time% done

注意:" Equipment.db"必须进行调整,因为搜索"设备2"也会找到" Equipment20",Equipment21" ......" Equipment200" ...

答案 1 :(得分:1)

由于您只提供有关文件结构的模糊信息,我建议

@echo off
for /f "tokens=1*delims=:" %%a in (details.db) do >>%%a.dat echo %%b

假设details.db中的每个条目的格式为

equipment1234:details