shyang Posted January 3, 2014 Share Posted January 3, 2014 Hello all Recently I got to know autoit, and just a beginner. though I searched many forum articles, I couldn't find what I want to do exactly. So Anyone can help me please. For example, I have contents.txt file like below; #cat contents.txt asdfqgaghas sdfqwert dfgasdfweg tom is user_admin-user=12345678 testcenter1 sam is user_admin-user=12341238 testcenter2 markis user_admin-user=56234238 testcenter3 What I want to do are; - just save "user_admin-user=########" to username.txt ,not including other strings(eg: tome is, sam is, mark is ) - and save "testcenter#" maching with "user_admin-user=########" to testcenter.txt - and I want to delete all lines which don't have user_admin-user=######## string, and save as contents.after.txt so Final output will be like ; #cat username.txt user_admin-user=12345678 user_admin-user=12341238 user_admin-user=56234238 #cat testcenter.txt testcenter1 testcenter2 testcenter3 #cat contents.after.txt tom is user_admin-user=12345678 testcenter1 sam is user_admin-user=12341238 testcenter2 markis user_admin-user=56234238 testcenter3 I was trying to find ; - just copy 24characters starting from 7th character,but I'm sure there might be more efficient way to do this. Anyone can help me on this. Thanks in advance & Happy New year. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 3, 2014 Moderators Share Posted January 3, 2014 shyang,Not too difficult: expandcollapse popup#include <Array.au3> ; Simulate reading contents.txt into an array with FileReadToArray Global $aLines[] = [ _ "asdfqgaghas", _ "sdfqwert", _ "dfgasdfweg", _ "tom is user_admin-user=12345678 testcenter1", _ "sam is user_admin-user=12341238 testcenter2", _ "markis user_admin-user=56234238 testcenter3" _ ] ; Areate arrays large enough to hold the required data Global $aUserName[UBound($aLines)] Global $aTestCenter[UBound($aLines)] Global $aAfter[UBound($aLines)] ; Create 3 counters Global $iUserName = 0, $iTestCenter = 0, $iAfter = 0 For $i = 0 To UBound($aLines) - 1 ; Read the line $sLine = $aLines[$i] ; Determine what to do with it If StringInStr($sLine, "testcenter") Then ; Add the required data to the relevant arrays $aUserName[$iUserName] = StringRegExpReplace($sLine, "^.*(user_admin-user=\d*).*$", "$1") $aTestCenter[$iTestCenter] = StringRegExpReplace($sLine, "^.*(testcenter\d*)$", "$1") ; Increase the counters $iUserName += 1 $iTestCenter += 1 Else ; Add line to the array $aAfter[$iAfter] = $sLine ; Increase the counter $iAfter += 1 EndIf Next ; Remove unused elements ReDim $aUserName[$iUserName] ReDim $aTestCenter[$iTestCenter] ReDim $aAfter[$iAfter] ; And here is the result ready to be written to file with _FileWriteFromArray _ArrayDisplay($aUserName, "username.txt", Default, 8) _ArrayDisplay($aTestCenter, "testcenter.txt", Default, 8) _ArrayDisplay($aAfter, "after.txt", Default, 8)I hope the comments are clear, but please ask if you have any questions. M23 Synapsee 1 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...
shyang Posted January 3, 2014 Author Share Posted January 3, 2014 Thank you very much M23, does this actually create output file ? On my testing with the above script, It showed exactly what I want to do, but output files were not created. anything I miss maybe ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 3, 2014 Moderators Share Posted January 3, 2014 shyang, but output files were not created; And here is the result ready to be written to file with _FileWriteFromArrayThat bit was left to you - I even gave you the name of the function to use. 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 Link to comment Share on other sites More sharing options...
shyang Posted January 3, 2014 Author Share Posted January 3, 2014 aha~! Let me try with _FileWriteFromArray,,Thank you very much~ Link to comment Share on other sites More sharing options...
mikell Posted January 3, 2014 Share Posted January 3, 2014 (edited) Melba, Why on earth go through arrays ? $str = "asdfqgaghas" & @crlf & _ "sdfqwert" & @crlf & _ "dfgasdfweg" & @crlf & _ "tom is user_admin-user=12345678 testcenter1" & @crlf & _ "sam is user_admin-user=12341238 testcenter2" & @crlf & _ "markis user_admin-user=56234238 testcenter3" ; $str = FileRead("contents.txt") ; <<< as enunciated $username = StringRegExpReplace($str, '(?s).+?(user_admin-user=\d+)\V+', "$1" & @crlf) msgbox(0,"", $username) ; FileWrite("username.txt", $username) ; << ditto $testcenter = StringRegExpReplace($str, "(?s).+?(testcenter\d+)", "$1" & @crlf) msgbox(0,"", $testcenter) $after = StringRegExpReplace($str, '(?m)^[^=_]+\v+', "") msgbox(0,"", $after) Edited January 3, 2014 by mikell Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 3, 2014 Moderators Share Posted January 3, 2014 mikell, Why on earth go through arrays ?Because I am but a simple soul and cannot write SREs like that. M23 kylomas 1 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...
mikell Posted January 3, 2014 Share Posted January 3, 2014 Can't believe this I rather think you have too many things to think about 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