Jump to content

searching for text and reading complete line.


samueltb
 Share

Recommended Posts

I'm looking for a script that will export a reg branch and then search it returning the value, I have to export the full key as some of the values I am looking are held within a string value key.

So far I can export the key and search using the dos find command but this creates another file which is then displayed and every search command inserts header into second txt file, I'm looking for a way to search a text file and return the complete line of text.

what I'm doing

#include <GUIConstants.au3>

FileDelete ("c:\alt_details.txt")

RunWait(@COMSPEC & " /c regedit.Exe /e c:\alt_details.txt ""HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Client Service""")

RunWait(@COMSPEC & " /c find ""TcpAddr="" c:\alt_details.txt >22.txt")

RunWait(@COMSPEC & " /c find ""IP-Address="" c:\alt_details.txt >>22.txt")

RunWait(@COMSPEC & " /c find ""Name="" c:\alt_details.txt >>22.txt")

RunWait(@COMSPEC & " /c find ""Computer-Name="" c:\alt_details.txt >>22.txt")

StringRegExp

values returned at present

---------- C:\ALT_DETAILS.TXT

TcpAddr=1.2.4.1

---------- C:\ALT_DETAILS.TXT

IP-Address=1.1.1.15

---------- C:\ALT_DETAILS.TXT

Name=SAS-A1SA

Computer-Name=SAS-A1SA

Domain-Name=

DNS-Domain-Name=

ConsoleName=

Product-Name=HP Compaq dc7100 SFF(DX878AV)

---------- C:\ALT_DETAILS.TXT

Computer-Name=SAS-A1SA

What i would like to get to if possible

TcpAddr=1.2.4.1

IP-Address=1.1.1.15

Name=SAS-A1SA

Computer-Name=SAS-A1SA

Domain-Name=

DNS-Domain-Name=

ConsoleName=

Product-Name=HP Compaq dc7100 SFF(DX878AV)

Computer-Name=SAS-A1SA

Thanks for any help.

Link to comment
Share on other sites

I'm looking for a script that will export a reg branch and then search it returning the value, I have to export the full key as some of the values I am looking are held within a string value key.

So far I can export the key and search using the dos find command but this creates another file which is then displayed and every search command inserts header into second txt file, I'm looking for a way to search a text file and return the complete line of text.

what I'm doing

#include <GUIConstants.au3>

FileDelete ("c:\alt_details.txt")

RunWait(@COMSPEC & " /c regedit.Exe /e c:\alt_details.txt ""HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Client Service""")

RunWait(@COMSPEC & " /c find ""TcpAddr="" c:\alt_details.txt >22.txt")

RunWait(@COMSPEC & " /c find ""IP-Address="" c:\alt_details.txt >>22.txt")

RunWait(@COMSPEC & " /c find ""Name="" c:\alt_details.txt >>22.txt")

RunWait(@COMSPEC & " /c find ""Computer-Name="" c:\alt_details.txt >>22.txt")

StringRegExp

values returned at present

---------- C:\ALT_DETAILS.TXT

TcpAddr=1.2.4.1

---------- C:\ALT_DETAILS.TXT

IP-Address=1.1.1.15

---------- C:\ALT_DETAILS.TXT

Name=SAS-A1SA

Computer-Name=SAS-A1SA

Domain-Name=

DNS-Domain-Name=

ConsoleName=

Product-Name=HP Compaq dc7100 SFF(DX878AV)

---------- C:\ALT_DETAILS.TXT

Computer-Name=SAS-A1SA

What i would like to get to if possible

TcpAddr=1.2.4.1

IP-Address=1.1.1.15

Name=SAS-A1SA

Computer-Name=SAS-A1SA

Domain-Name=

DNS-Domain-Name=

ConsoleName=

Product-Name=HP Compaq dc7100 SFF(DX878AV)

Computer-Name=SAS-A1SA

Thanks for any help.

Rather than use lots of FIND commands you could do something like this. (This is just written as a suggestion and not tried.)

FileDelete ("c:\alt_details.txt")

RunWait(@COMSPEC & " /c regedit.Exe /e c:\alt_details.txt  ""HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Client Service""")
$text = FileRead("C:\alt_details.txt")

;the things we want to read
$items = "TcpAddr|IP-Address|Name|Computer-Name|Domain-Name|DNS-Domain-Name|ConsoleName|Product-Name"
$items = StringSplit($Items);convert to array

$hFile = FileOpen("22.txt",2);open to write results, erasing previous contents
$OutPut = '';no results to start with

for $n = 1 to $Items[0];for each of the items
    $OutPut &= GetlineBeginning($Text,$Items[$n] & '=') & @CRLF
next

FileWrite($hFile,$OutPut)
FileClose($hFile)




Func GetlineBeginning($SearchText,$find)
    Local $pos = StringinStr($SearchText,$find)
    Local $Result = '',$Chr
    Local $Length = Stringlen($SearchText)
    While 1
        $chr = StringMid($SearchText,$pos,1)
        if $Chr = @CR or $Chr = @LF then exitloop
        $Result &= $Chr
        $Pos += 1
        if $Pos > $Length then ExitLoop
    Wend
    return $Result 
endfunc
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...