Jump to content

Recommended Posts

Posted (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 by florian2
  • Moderators
Posted

florian2,

So what code have you tried that has not worked?

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)

tip: you could have a look to the StringInStr() and to the AND logical operator .....

... sorry, I see you want to use regexp ....

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted (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 by florian2
Posted

I found that, am i in the right direction ? 

#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)

 

Posted

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

 

Posted (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 by Earthshine

My resources are limited. You must ask the right questions

 

Posted (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 by florian2

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...