learn Posted July 2, 2014 Posted July 2, 2014 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...
jdelaney Posted July 2, 2014 Posted July 2, 2014 (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 July 2, 2014 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 Melba23 Posted July 2, 2014 Moderators Posted July 2, 2014 learn,Welcome to the AutoIt forums. Something like this should be what you need:expandcollapse popup#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 filePlease ask if you have any questions. M23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
learn Posted July 2, 2014 Author Posted July 2, 2014 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. learn, Welcome to the AutoIt forums. Something like this should be what you need: expandcollapse popup#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
learn Posted July 2, 2014 Author Posted July 2, 2014 _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 Melba23 Posted July 2, 2014 Moderators Posted July 2, 2014 learn, the 1st and 2rd file are already existingI 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 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
learn Posted July 2, 2014 Author Posted July 2, 2014 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
learn Posted July 2, 2014 Author Posted July 2, 2014 (edited) Sorry m23, I can not link the $sData to the _FileReadToArray learn Edited July 2, 2014 by Melba23 Removed GIANT quote
Moderators Melba23 Posted July 2, 2014 Moderators Posted July 2, 2014 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 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
learn Posted July 2, 2014 Author Posted July 2, 2014 (edited) Thank you very much M23, Exactly what I am looking for. Nothing to say, Again Thank you very much! learn Edited July 2, 2014 by Melba23 Removed another quote
Moderators Melba23 Posted July 2, 2014 Moderators Posted July 2, 2014 (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 July 2, 2014 by Melba23 Typo 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
learn Posted July 3, 2014 Author Posted July 3, 2014 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 Melba23 Posted July 3, 2014 Moderators Posted July 3, 2014 learn,Did you actually read and understand what I posted above and to which I have since referred you several times? 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 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now