How to search for string pattern within text file?
I'm using a VbScript to search within a text file of the following sample output:
My objective is to retrieve out only the file path from the following sample output. Note that the control ID is fixed and everything else is dynamic. Someone help out please? thanks!
~~~~~~~~~~~~~~
============================
Control 127256:
name;db_size;owner;dbid;created;status;compatibility_level
----;-------;-----;----;-------;------;-------------------
master; 4.75 MB;sa;1;Apr 8 2003;Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=SIMPLE, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics;100
name;fileid;filename;filegroup;size;maxsize;growth;usage
----;------;--------;---------;----;-------;------;-----
master;1;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\master.mdf;PRIMARY;4096 KB;Unlimited;10%;data only
mastlog;2;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\mastlog.ldf;NULL;768 KB;Unlimited;10%;log only
name;db_size;owner;dbid;created;status;compatibility_level
----;-------;-----;----;-------;------;-------------------
tempdb; 2.75 MB;sa;2;Oct 11 2011;Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=SIMPLE, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics;100
name;fileid;filename;filegroup;size;maxsize;growth;usage
----;------;--------;---------;----;-------;------;-----
tempdev;1;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\tempdb.mdf;PRIMARY;2048 KB;Unlimited;10%;data only
templog;2;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\templog.ldf;NULL;768 KB;Unlimited;10%;log only
name;db_size;owner;dbid;created;status;compatibility_level
----;-------;-----;----;-------;------;-------------------
model; 1.75 MB;sa;3;Apr 8 2003;Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=SIMPLE, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics;100
name;fileid;filename;filegroup;size;maxsize;growth;usage
----;------;--------;---------;----;-------;------;-----
modeldev;1;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\model.mdf;PRIMARY;1280 KB;Unlimited;1024 KB;data only
modellog;2;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\modellog.ldf;NULL;512 KB;Unlimited;10%;log only
name;db_size;owner;dbid;created;status;compatibility_level
----;-------;-----;----;-------;------;---------开发者_运维技巧----------
msdb; 12.63 MB;sa;4;Apr 2 2010;Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=SIMPLE, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsFullTextEnabled;100
name;fileid;filename;filegroup;size;maxsize;growth;usage
----;------;--------;---------;----;-------;------;-----
MSDBData;1;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\MSDBData.mdf;PRIMARY;12416 KB;Unlimited;10%;data only
MSDBLog;2;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\MSDBLog.ldf;NULL;512 KB;2147483648 KB;10%;log only
~~~~~~~~~~~~~~
============================
Control 127257:
What have you tried so far?
I would start with reading the test in from the text file (line by line or all at once), then SPLIT the text on the ;
inputTextSplit = Split(1, inputText, ";")
Then you can loop over the array and look for indicators that it is a file path. e.g. starting with c: or contains \
For i = 0 to UBound(inputTestSplit)
Loop
精彩评论