Find text inside text file with script and output

Posted on 2008-11-06
Last Modified: 2012-05-05
I am trying to find and gather data from a text file.  I will need to do it with a script file.  Batch or VBScript.  The data in the file is below.  What I need to input is one of the ip addresses and what I need outputted is the Unique ID on the same line.   So if I pass the script I need it to output 00-00-02-00.  Thank you !

Changed the current scope context to scope.

  Reservation Address -    Unique ID                          
===============================================================      -    00-00-02-00      -    00-00-02-02      -    00-00-02-03      -    00-00-02-04      -    00-00-02-05      -    00-00-02-06      -    00-00-02-08
No of ReservedIPs : 7 in the Scope :
Command completed successfully.
Question by:heliontech
    LVL 65

    Accepted Solution

    Hi, try this VBS code.


    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Const intForReading = 1
    strTextFile = "C:\Temp\Temp\Test Script\Test.txt"
    strInput = InputBox("What data are you looking for?", "Data")
    Set objFile = objFSO.OpenTextFile(strTextFile, intForReading, False)
    strFound = ""
    While Not objFile.AtEndOfStream
    	strLine = objFile.ReadLine
    	If InStr(strLine, strInput) > 0 Then strFound = Mid(strLine, InStrRev(strLine, " ") + 1)
    If strFound = "" Then
    	WScript.Echo strInput & " was not found."
    	WScript.Echo "Data found for " & strInput & VbCrLf & strFound
    End If

    Open in new window


    Author Closing Comment

    Handy and quick to boot ! Thank you so much.
    LVL 65

    Expert Comment

    No problem. Thanks for the grade.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
    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 …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    737 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