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
414 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 500 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now