Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Vbscript: I want to search in a text file for a string and return the line of the string

Posted on 2011-03-14
2
Medium Priority
?
461 Views
Last Modified: 2012-05-11
how can i achieve this ?
0
Comment
Question by:itbabe
2 Comments
 
LVL 8

Expert Comment

by:jsvor
ID: 35129891
Without knowing what you have already you can view this article that explains how to do it.
http://blogs.technet.com/b/heyscriptingguy/archive/2007/03/29/how-can-i-search-a-text-file-for-strings-meeting-a-specified-pattern.aspx
0
 
LVL 8

Accepted Solution

by:
GundogTrainer earned 2000 total points
ID: 35130306
Something like below should work - (similar code to your other question.)
Const ForReading = 1

CurrentLineNum=0
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile ("TextFileforReading.txt", ForReading)

Do Until oTextFile.AtEndOfStream
CurrentLineNum=CurrentLineNum+1
    sLine = oTextFile.ReadLine
    If instr(sline,"LookForMe")
             WScript.Echo CurrentLineNum,sLine
           Next
    End If
Loop

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question