Solved: Where search match found write following line as well

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

JuniperGreen

Thread Starter
Joined
Jan 3, 2013
Messages
25
I have a file which holds lines of text. One line of text indicates a file's location the following line holds a description of the file. I want to be able to search the file using "the directory" as the keyword and where a match is found extract the following line also so I have both the file location and description. For example by searching for one of the directories such as "/s/" I would be able to identify all the files which are in it along with their descriptions. The script below lets me identify all the directory matches but I am stumped as to how I can extract the line following the match so that I have the description as well. There is no way I can search for the descriptions as they are unique.

Any help on how I might achieve this would be appreciated

Thank you


Code:
Const ForReading = 1

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "./s/"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("F:\H&S_Safety_Matters\H&S_Items.txt", ForReading)

Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)  
    If colMatches.Count > 0 Then
        For Each strMatch in colMatches   
            Wscript.Echo strSearchString 
       
Next
    End If
Loop

objFile.Close
 
Joined
Jun 8, 2001
Messages
2,583
Read\write the next line inside the IF statement. Also not sure the RegEx business is necessary.

Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
IF InString(strSearchString,"./s/") > 0 THEN
Wscript.Echo strSearchString 'shows match
strSearchString = objFile.ReadLine
Wscript.Echo strSearchString 'shows next line
End IF
Loop
 
Joined
Jun 8, 2001
Messages
2,583
This might be more what you want..
Code:
Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
IF InString(strSearchString,"./s/") > 0 THEN
  strDisplay = "Match: " & strSearchString & VbCrLf   
  strSearchString = objFile.ReadLine
  strDisplay = strDisplay & "Discription: " & strSearchString
  Wscript.Echo strDisplay
End IF
Loop
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top