Zingzi Posted November 3, 2011 Share Posted November 3, 2011 Hello folks, I am a complete noob at this so forgive up front please. I have been messing around AutoIT the last few weeks and it has been so much fun! I'm hooked. I needed something light and portable and this fits the bill perfectly. Right now I am using it to gleam data from my network and splitting the data down into two ":" delimited txt files. All data is alphanumeric. The first txt file contains a data structure like this and is around 400 lines long: data1:data2 The second txt file contains a data structure like this and also is around 400 lines long: data2:data3 What I am trying to do, and failing at, is searching the first txt file for data1 to get data2 and then searching the second txt file using data2 to find data3. The end result would be a parsed txt file containing data1:data2:data3. I am not asking anyone to do this for me but rather point this noob in the right direction. Thanks Link to comment Share on other sites More sharing options...
jchd Posted November 3, 2011 Share Posted November 3, 2011 Welcome to the forum, That's a perfect job for two scripting dictionnaries (use forum's search feature). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 3, 2011 Moderators Share Posted November 3, 2011 (edited) Zingzi, Welcome to the AutoIt forum. Nice attitude there - it will help you a lot here! I would start by reading the files into arrays using _FileReadToArray. Then you can loop through the first file in a For...Next loop using StringInStr to detect the presence of "data1". if it is there you can extract "data2" in a number of ways - perhaps using StringSplit. Once you have "data2" you repeat the process on the second file to find "data3". Then you concatenate the 3 bits of data and use FileWrite to add it to a new file. Give it a try - you know where we are if you run into difficulties. M23 Edit: Or you can try jchd's idea. Edited November 3, 2011 by Melba23 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 Link to comment Share on other sites More sharing options...
Zingzi Posted November 3, 2011 Author Share Posted November 3, 2011 Thanks for the kick in the right direction M23. Link to comment Share on other sites More sharing options...
czardas Posted November 3, 2011 Share Posted November 3, 2011 (edited) If your files are using delimitered strings you might want to use a two dimensional array. I recently wrote a script which you might find useful. You will need to run the code below. Although it's intended for csv you can set the delimiter to whatever you like. #include <Array.au3> ; For array display purposes #include <CSVSplit.au3> Dim $file = FileOpen("test.txt", 0) If $file = -1 Then ; Check if file opened for reading OK MsgBox(0, "Error", "Unable to open file.") Exit EndIf Dim $sDataString = FileRead($file) FileClose($file) Dim $aArray = _CSVSplit($sDataString, ":") ; Using colon delimiter _ArrayDisplay($aArray) Once your data is organized in an array you can loop through each row, and then each column using two nested For loops. Word of warning, the only problem that could arise is if your file contains double quote characters, since the script was originally designed to be used with csv. Edit : just fixed an error in the code Edited November 3, 2011 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jchd Posted November 3, 2011 Share Posted November 3, 2011 I apologize for laconic post above (I was a little upset with unreliable 3G link that trashed typed text 3 times). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
czardas Posted November 4, 2011 Share Posted November 4, 2011 It's given me something to research jchd. There's so much I haven't tried. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Zingzi Posted November 4, 2011 Author Share Posted November 4, 2011 no worries there jchd. Link to comment Share on other sites More sharing options...
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