florian2 Posted March 1, 2018 Share Posted March 1, 2018 (edited) I want the script to detect and erase every line who have the letters "a" and "e" in it. ex.txt : aeuio euia nike nujik I want the script to erase "aeuio" and "euia", so that it remain the following : nike nujik thanks ! Edited March 1, 2018 by florian2 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 1, 2018 Moderators Share Posted March 1, 2018 florian2, So what code have you tried that has not worked? 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...
florian2 Posted March 1, 2018 Author Share Posted March 1, 2018 https://www.autoitscript.fr/autoit3/docs/tutorials/regexp/regexp.htm the exemples here show how to find the letters in a specific order, but not in random place Link to comment Share on other sites More sharing options...
jguinch Posted March 1, 2018 Share Posted March 1, 2018 10 minutes ago, florian2 said: I want the script to detect and erase every line who have the letters "a" and "e" in it. Maybe the script will detect the "e" in "nike", not like you (I joke) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
florian2 Posted March 1, 2018 Author Share Posted March 1, 2018 it need to have both a and e so nike need to remain Link to comment Share on other sites More sharing options...
Gianni Posted March 1, 2018 Share Posted March 1, 2018 (edited) tip: you could have a look to the StringInStr() and to the AND logical operator ..... ... sorry, I see you want to use regexp .... Edited March 1, 2018 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
florian2 Posted March 1, 2018 Author Share Posted March 1, 2018 nah any tip is welcomed Link to comment Share on other sites More sharing options...
mikell Posted March 1, 2018 Share Posted March 1, 2018 (edited) This removes lines which contain both "a" and "e" $txt = "aeuio" & @crlf & _ "euia" & @crlf & _ "nike" & @crlf & _ "nujik" $txt = StringRegExpReplace($txt, '(?m)(?|^.*?a.*?e.*$|^.*?e.*?a.*$)\R?', "") msgbox(0,"", $txt) Edited March 1, 2018 by mikell Link to comment Share on other sites More sharing options...
Subz Posted March 1, 2018 Share Posted March 1, 2018 FIrstly I suck at RegEx so take the following with a grain of salt. #include <Array.au3> Local $aSample[4] = ["aeuio", "euia", "nike", "nujik"] _ArrayDisplay($aSample, "Sample Before") For $i = UBound($aSample) - 1 To 0 Step - 1 If StringRegExp($aSample[$i], "a.*e|e.*a") = 1 Then _ArrayDelete($aSample, $i) Next _ArrayDisplay($aSample, "Sample After") Earthshine 1 Link to comment Share on other sites More sharing options...
mikell Posted March 1, 2018 Share Posted March 1, 2018 Sorry. I didn't pay attention to the "both". Previous post edited Link to comment Share on other sites More sharing options...
florian2 Posted March 1, 2018 Author Share Posted March 1, 2018 (edited) thanks to both, but my challenge is to erase the lines from an external .txt, wich itself have many lines. Like, i want to rewrite a new .txt file without the lines, or directly delete the concerned lines from it. Edited March 1, 2018 by florian2 Link to comment Share on other sites More sharing options...
Subz Posted March 1, 2018 Share Posted March 1, 2018 Just use FileRead then FileOpen, FileWrite and then FileClose with the string or array results (I would go with mikell example) Link to comment Share on other sites More sharing options...
mikell Posted March 1, 2018 Share Posted March 1, 2018 ...or _FileReadToArray and _FileWriteFromArray in a similar way (with Subz example) Link to comment Share on other sites More sharing options...
florian2 Posted March 1, 2018 Author Share Posted March 1, 2018 ok thanks ill try that Link to comment Share on other sites More sharing options...
florian2 Posted March 1, 2018 Author Share Posted March 1, 2018 I found that, am i in the right direction ? expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> ;Assign the file path to a variable Local $sFilePath = "C:\AutomationDevelopers\temp.txt" ;Open the file temp.txt in append mode. If the folder C:\AutomationDevelopers does not exist, it will be created. Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND + $FO_CREATEPATH) ;Display a message box in case of any errors. If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when opening the file.") EndIf ;Write a set of lines for demonstration FileWriteLine($hFileOpen, "This is the first line") FileWriteLine($hFileOpen, "This is the second line") FileWriteLine($hFileOpen, "This is the third line") FileWriteLine($hFileOpen, "This is the last line") ;Set the file position to beginning for reading the data from the beginning of the file. FileSetPos($hFileOpen, 0, $FILE_BEGIN) ;Read the 2nd line of data from the file using the handle returned by FileOpen Local $sFileRead = FileReadLine ($hFileOpen,2) ;Display the data. MsgBox($MB_SYSTEMMODAL, "Automation Developers", "The second line is:" & @CRLF & $sFileRead) ;Read the last line of data from the file using the handle returned by FileOpen Local $sFileRead = FileReadLine ($hFileOpen,-1) ;Display the data. MsgBox($MB_SYSTEMMODAL, "Automation Developers", "The last line is:" & @CRLF & $sFileRead) ;Close the handle returned by FileOpen. FileClose($hFileOpen) Link to comment Share on other sites More sharing options...
florian2 Posted March 1, 2018 Author Share Posted March 1, 2018 (edited) But there is millions of lines to check, so i dunno if fileopen/read can do the trick then Edited March 1, 2018 by florian2 Link to comment Share on other sites More sharing options...
Earthshine Posted March 1, 2018 Share Posted March 1, 2018 reading one line at a time to an array, then process array? will that do it? that way, it will take many small swipes at the line. you could even break it down to word by word search, no? My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
mikell Posted March 1, 2018 Share Posted March 1, 2018 Maximum string length in AutoIt is 2,147,483,647 . Have a try... Link to comment Share on other sites More sharing options...
Earthshine Posted March 1, 2018 Share Posted March 1, 2018 (edited) I was thinking going through the file, like this above... check it. there is example code in that thread I think you might find interesting. Happy programming. Edited March 1, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
florian2 Posted March 1, 2018 Author Share Posted March 1, 2018 (edited) so far : #include <file.au3> $file = FileOpen("C:\AutomationDevelopers\temp.txt", 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $line= StringRegExpReplace($line, '(?m)(?|^.*?a.*?e.*$|^.*?e.*?a.*$)\R?', "") MsgBox(0,'',$line) WEnd FileClose($file) at least it show correcly line by line the right word, that encouraging. but how to actually delete the line in the file ? Edited March 1, 2018 by florian2 Earthshine 1 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