【发布时间】:2014-01-30 04:50:56
【问题描述】:
我有一个日志文件Source.txt,其内容结构如下:
Handle v3.51
Copyright (C) 1997-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
------------------------------------------------------------------------------
DataSource.exe pid: 5860 USER\DEVELOPMENT
5EC: File (R--) G:\apps\OracleClient\product\11.1.0\client_2\RDBMS\mesg\ocius.msb
600: File (R--) G:\apps\OracleClient\product\11.1.0\client_2\RDBMS\mesg\ocius.msb
614: File (R--) G:\apps\OracleClient\product\11.1.0\client_2\RDBMS\mesg\ocius.msb
628: File (R--) G:\apps\OracleClient\product\11.1.0\client_2\RDBMS\mesg\ocius.msb
834: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP1_RulesLogFiles\1-28-2014_Timer.log
838: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP1_RulesLogFiles\1-28-2014_Debug.log
854: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP1_RulesLogFiles\1-28-2014_Timer.log
858: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP1_RulesLogFiles\1-28-2014_Debug.log
874: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP1_RulesLogFiles\1-28-2014_Timer.log
878: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP1_RulesLogFiles\1-28-2014_Debug.log
1058: File (RW-) C:\Windows\winsxs\amd64_microsoft.vc80.atl_1fc8b3b9a1e18e3b_8.0.50727.4053_none_8a1a02152edb659b
------------------------------------------------------------------------------
DataSource.exe pid: 10568 USER\DEVELOPMENT
1074: File (RW-) C:\Windows\winsxs\amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4053_none_88e046c92fae6f57
1078: File (RW-) C:\Windows\winsxs\amd64_microsoft.vc80.atl_1fc8b3b9a1e18e3b_8.0.50727.4053_none_8a1a02152edb659b
8F4: File (RW-) C:\Windows\winsxs\amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4053_none_88e046c92fae6f57
908: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP2_RulesLogFiles\1-28-2014_Timer.log
90C: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP2_RulesLogFiles\1-28-2014_Debug.log
928: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP2_RulesLogFiles\1-28-2014_Timer.log
92C: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP2_RulesLogFiles\1-28-2014_Debug.log
948: File (RW-) G:\apps\Oracle\Middleware\user_projects\epmsystem8\products\FinancialManagement\Server Working Folder\APP2_RulesLogFiles\1-28-2014_Timer.log
1064: File (RW-) C:\Windows\winsxs\amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4053_none_88e046c92fae6f57
1068: File (RW-) C:\Windows\winsxs\amd64_microsoft.vc80.atl_1fc8b3b9a1e18e3b_8.0.50727.4053_none_8a1a02152edb659b
| |
| |
| |
and so on......
我想实现以下目标:
-
搜索第一次出现的“DataSource.exe”,然后搜索 对于
(APP1 APP2 APP3 APP4 APP5 APP6 APP7 APP8 APP9)中任何一个单词的第一次出现,我们假设找到了 APP1 单词 将以下输出发送到文件“Output.txt”:DataSource.exe pid: 5860 USER\DEVELOPMENT APP1 -
然后搜索“DataSource.exe”的第二次出现,然后 再次搜索
(APP1 APP2 APP3 APP4 APP5 APP6 APP7 APP8 APP9)中任何一个单词的第一次出现[我们可以丢弃已经找到的单词],让我们假设 APP2 单词 找到然后将以下输出附加到同一文件“Output.txt”:DataSource.exe pid: 10568 USER\DEVELOPMENT APP2等等..
我正在使用以下工作脚本:
@ECHO OFF
setlocal enabledelayedexpansion
SET "keystring1="
(
FOR /f "delims=" %%a IN (
Source.txt
) DO (
ECHO %%a|FIND "DataSource.exe" >NUL
IF NOT ERRORLEVEL 1 SET keystring1=%%a
FOR %%b IN (APP1 APP2 APP3 APP4 APP5 APP6 APP7 APP8 APP9 ) DO (
ECHO %%a|FIND "%%b" >NUL
IF NOT ERRORLEVEL 1 IF DEFINED keystring1 CALL ECHO(%%keystring1%% %%b&SET "keystring1="
)))>Output.txt
GOTO :EOF
问题:
我在这里遇到的问题是 Source.txt file of size 312 KB ,即使只有这 9 个应用程序,这个脚本也会占用 4 minutes to produce Output.txt ,这似乎是相当长的时间。
无论如何我想减少这个时间,而不使用任何额外的批处理文件。请问有什么解决方法吗?
*具体应用名称与APP1、APP2...等不同。
【问题讨论】:
-
不是搜索进程然后确定它打开了哪些文件,而是枚举文件 (
dir) 并为每个文件确定锁定它的进程 (handle file)
标签: windows string performance batch-file for-loop