Jump to content

Recommended Posts

Posted

Greeting,

new in Autoit, but kind of like it.

I have a request, but do not know how to do it, so ask in here, please give me some help.

I have a file which have all Microsoft patches installed information from one machine, as below:  1st file

   kb456780

   kb123456

   kb890445

 

I will build the second file include all the details information for that KB, like below:  2nd file

   kb000001 microsoft security patch

   kb000002 IE 20 patch

    ...

   kb123456 Office 2015 patch

   .....

   kb456780 Word security patch

    ......

   kb890445 Outlook 2019 security patch

   ......

   kb9999999 Microsoft windows 10 patch

 

 

What I am looking for is, this program will create a new file like below: 3rd file

   kb123456 Office 2015 patch

   kb456780 Word security patch

   kb890445 Outlook 2019 security patch

If the 1st file have kb666666 installed information, but I do not have information about that in 2nd file, then in the 3rd file add a line as below

kb666666 NO information.

 

Thanks

learning

online waiting...

Posted (edited)

_FileReadToArray the first file.  Loop through that, and use the return in a StringRegExp to grab the line from the second....read in the second with FileRead.  Use _FileCreate for a new file, and FileWrite to write to it.

Click for samples:

_FileReadToArray
StringRegexp
FileRead
FileWrite
_FileCreate
For...In...Next
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
  • Moderators
Posted

learn,

Welcome to the AutoIt forums. :)

Something like this should be what you need:

#include <Array.au3>
#include <StringConstants.au3>

; Simulate files
$sData = "kb000001 microsoft security patch" & @CRLF & _
    "kb000002 IE 20 patch" & @CRLF & _
    "kb123456 Office 2015 patch" & @CRLF & _
    "kb456780 Word security patch" & @CRLF & _
    "kb890445 Outlook 2019 security patch" & @CRLF & _
    "kb9999999 Microsoft windows 10 patch"

$sFile =  "kb456780" & @CRLF & _
    "kb123456" & @CRLF & _
    "kb234567" & @CRLF & _
    "kb890445"

; Simulate loading files - use _FileListtoArray to do this
$aData = StringSplit($sData, @CRLF, $STR_ENTIRESPLIT)
_ArrayDisplay($aData, "Data", Default, 8) ; Just for demo
$aFile = StringSplit($sFile, @CRLF, $STR_ENTIRESPLIT)
_ArrayDisplay($aFile, "File", Default, 8) ; Just for demo

; Loop through file to check KB values
For $i = 1 To $aFile[0]
    ; Extract value
    $sKB = $aFile[$i]
    ; Search for the KB in the data array
    $iIndex = _ArraySearch($aData, $sKB, 1, 0, 0, 1)
    If $iIndex = -1 Then
        $aFile[$i] &= " No information"
    Else
        $aFile[$i] = $aData[$iIndex]
    EndIf
Next

; And here is the resultant array
_ArrayDisplay($aFile, "", Default, 8) ; Just for demo

; Use FileWriteFromArray to write the new file
Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

M23,

Thank you very very much, But as my example, the 1st and 2rd file are already existing

1st file

   kb456780

   kb123456

   kb890445

 

2nd file

   kb000001 microsoft security patch

   kb000002 IE 20 patch

    ...

   kb123456 Office 2015 patch

   .....

   kb456780 Word security patch

    ......

   kb890445 Outlook 2019 security patch

   ......

   kb9999999 Microsoft windows 10 patch

 

I try to create a utility, use this utility to general the 3rd file, like below

   kb123456 Office 2015 patch

   kb456780 Word security patch

   kb890445 Outlook 2019 security patch

If the 1st file have kb666666 installed information, but I do not have information about that in 2nd file, then in the 3rd file add a line as below

kb666666 NO information.

 

  On 7/2/2014 at 3:13 PM, Melba23 said:

learn,

Welcome to the AutoIt forums. :)

Something like this should be what you need:

#include <Array.au3>
#include <StringConstants.au3>

; Simulate files
$sData = "kb000001 microsoft security patch" & @CRLF & _
    "kb000002 IE 20 patch" & @CRLF & _
    "kb123456 Office 2015 patch" & @CRLF & _
    "kb456780 Word security patch" & @CRLF & _
    "kb890445 Outlook 2019 security patch" & @CRLF & _
    "kb9999999 Microsoft windows 10 patch"

$sFile =  "kb456780" & @CRLF & _
    "kb123456" & @CRLF & _
    "kb234567" & @CRLF & _
    "kb890445"

; Simulate loading files - use _FileListtoArray to do this
$aData = StringSplit($sData, @CRLF, $STR_ENTIRESPLIT)
_ArrayDisplay($aData, "Data", Default, 8) ; Just for demo
$aFile = StringSplit($sFile, @CRLF, $STR_ENTIRESPLIT)
_ArrayDisplay($aFile, "File", Default, 8) ; Just for demo

; Loop through file to check KB values
For $i = 1 To $aFile[0]
    ; Extract value
    $sKB = $aFile[$i]
    ; Search for the KB in the data array
    $iIndex = _ArraySearch($aData, $sKB, 1, 0, 0, 1)
    If $iIndex = -1 Then
        $aFile[$i] &= " No information"
    Else
        $aFile[$i] = $aData[$iIndex]
    EndIf
Next

; And here is the resultant array
_ArrayDisplay($aFile, "", Default, 8) ; Just for demo

; Use FileWriteFromArray to write the new file
Please ask if you have any questions. :)

M23

 

 

Thanks again,

learn

Posted
  On 7/2/2014 at 3:10 PM, jdelaney said:

 

_FileReadToArray the first file.  Loop through that, and use the return in a StringRegExp to grab the line from the second....read in the second with FileRead.  Use _FileCreate for a new file, and FileWrite to write to it.

Click for samples:

_FileReadToArray
StringRegexp
FileRead
FileWrite
_FileCreate
For...In...Next

 

thanks for quick reply

learn

  • Moderators
Posted

learn,

 

  Quote

the 1st and 2rd file are already existing

I realise that - I used the first part of the code to simulate the files so that the data could be put into arrays for use. As I said in the comments, you would use _FileReadToArray to create the arrays directly from the files. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

  On 7/2/2014 at 3:29 PM, Melba23 said:

learn,

 

I realise that - I used the first part of the code to simulate the files so that the data could be put into arrays for use. As I said in the comments, you would use _FileReadToArray to create the arrays directly from the files. :)

M23

 

Thanks,

Will test and let you know the result.

again thank you :)

learn

Posted (edited)

Sorry m23,

 

I can not link the $sData to the _FileReadToArray

 

learn

Edited by Melba23
Removed GIANT quote
  • Moderators
Posted

learn,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily. ;)

This is how you read the files directly:

#include <Array.au3>
#include <File.au3>
#include <StringConstants.au3>

Global $aData, $aFile

; Use _FileListToArray to load the files
_FileReadToArray("Path_To_File2", $aData) ; This is the file with the full list of KBs
_ArrayDisplay($aData, "Data", Default, 8) ; Just for demo
_FileReadToArray("Path_To_File1", $aFile) ; This is the file for the particular machine
_ArrayDisplay($aFile, "File", Default, 8) ; Just for demo

; Loop through file to check KB values
For $i = 1 To $aFile[0]
    ; Extract value
    $sKB = $aFile[$i]
    ; Search for the KB in the data array
    $iIndex = _ArraySearch($aData, $sKB, 1, 0, 0, 1)
    If $iIndex = -1 Then
        $aFile[$i] &= " No information"
    Else
        $aFile[$i] = $aData[$iIndex]
    EndIf
Next

; And here is the resultant array
_ArrayDisplay($aFile, "", Default, 8) ; Just for demo

; Use FileWriteFromArray to write the new file - missing out the count element
_FileWriteFromArray("Path_To_File3", $aFile, 1)
Better? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

 

Thank you very much M23, Exactly what I am looking for.

 

Nothing to say, Again Thank you very much!

 

learn

Edited by Melba23
Removed another quote
  • Moderators
Posted (edited)

learn,

Glad I could help - but please read the first section of my last post about how not to quote on the forum when replying. ;)

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

  On 7/2/2014 at 6:25 PM, Melba23 said:

learn,

Glad I could help - but please read the first section of my last post about how not to quote on the forum when replying. ;)

M23

 

M23,

Sorry, one more request, the result file (say it is "c:tempresult.txt") was created., then how can I continue use excel to open it?

thanks

learn

  • Moderators
Posted

learn,

Did you actually read and understand what I posted above and to which I have since referred you several times? :huh:

  Quote

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

And I suggest you open a new thread about reading files into Excel - I do not use the specialist UDF written by water and so cannot really help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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