Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Read specific part of a text file:

$
0
0
I need to read a very specific part of a text file and I'm struggling:

My text file lists software (and GUIDs for software) that a particular PC has installed.

A single line of the text file reads like this and typically there may be up to 500 lines per file.


PCNAME   {24531475-94B9-4A91-B4AA-16158C6AE026} SOFTWARE NAME VER.NUM.OF.SW SOFTWARE SUPPLIER DATE

I know the name of the piece of software and I can find that inside the text file no problem, but I need to get the GUID out.

Here's what I've tried....

This didn't work, I tried using _StringBetween and stating the PCName and the Software to return the GUID but it didn't work.

[ autoit ]      
  #Include<File.au3> #Include <String.au3> $Hostname = ("PCNAME") $File = ("C:\Remote Uninstall\PCNAME.txt") $FileData = FileRead($File) $GUID = _StringBetween($FileData,$Hostname,"SOFTWARE NAME") MsgBox(0,"GUID",$GUID)

I also tried


[ autoit ]      
$Hostname = ("PCNAME") $File = ("C:\Remote Uninstall\PCNAME.txt") $FileData = FileRead($File) $Position = StringInStr($FileData,"SOFTWARE NAME") MsgBox(0,"SOFTWARE NAME","String SOFTWARE NAME occurs at position - " & $Position) $StartPos = $Position - 39                     ;take away 39 characters from the position found to move to the start of the GUID FileOpen($File,2) FileSetPos($File,$StartPos,0)                ;set position in the file FileRead($File,38)                                 ;tried reading 38 characters from the start position.



I feel String Regular Expression is probably what I need but I can't see how I'd use it?

Any ideas welcome, I've attached a sample text file.

Viewing all articles
Browse latest Browse all 12506

Trending Articles