60aside Posted April 20, 2010 Posted April 20, 2010 (edited) Hi, I nearly have this working but not quite, I have a text file $text and another text file $file3 that I read line by line and assign the variable $remove to each line like this:- For $i = 1 to _FileCountLines($file3) $remove = FileReadLine($file3, $i) I want to completely remove the line in $text if $remove exists (case insensitive) This line of code below is producing wierd results, :- StringRegExpReplace($text,"(?i)\h*\Q" & $remove & "\E.*\cM\cJ","") Can anyone help? Thanks. Edited April 20, 2010 by 60aside
MrMitchell Posted April 20, 2010 Posted April 20, 2010 So you are reading $file3 line-by-line then if that line occurs anywhere in $text you want it removed? StringRegExpReplace works on strings, not on files or file handles, is $text a string in your script?
60aside Posted April 20, 2010 Author Posted April 20, 2010 So you are reading $file3 line-by-line then if that line occurs anywhere in $text you want it removed? StringRegExpReplace works on strings, not on files or file handles, is $text a string in your script? I read the whole file $text = FileRead($file)
MrMitchell Posted April 20, 2010 Posted April 20, 2010 So what kind of weird results are you getting? Maybe try replacing your "\cM\cJ" with a "\v"?
60aside Posted April 21, 2010 Author Posted April 21, 2010 if the variable is in the line of text, it will remove the variable and everything on the line to the right of the variable. But anything to the left of the variable will then be added to the next line of text. Like if the variable is .net and the file is:- Microsoft .net framework Adobe Reader 9.0 after the script has run it will be MicrosoftAdobe Reader 9.0
MrMitchell Posted April 21, 2010 Posted April 21, 2010 (edited) Oh yea...in your StringRegExpReplace, make the ReplaceString @CRLF instead of "". Add: ...Either that or don't replace the carriage return and/or line feed in the first place. Edited April 21, 2010 by MrMitchell
60aside Posted April 21, 2010 Author Posted April 21, 2010 Oh yea...in your StringRegExpReplace, make the ReplaceString @CRLF instead of "".Add:...Either that or don't replace the carriage return and/or line feed in the first place.That seems to give me :-MicrosoftAdobe Reader 9.0what I need is:-Adobe Reader 9.0- I'm so close .. any other ideas? I need it to completely delete the whole line if my variable is present anywhere in the line.Thanks.
MrMitchell Posted April 21, 2010 Posted April 21, 2010 Add another ".*" in your RegEx before $remove:StringRegExpReplace($text,"(?i)\h*.*\Q" & $remove & "\E.*\v","")
60aside Posted April 21, 2010 Author Posted April 21, 2010 Add another ".*" in your RegEx before $remove:StringRegExpReplace($text,"(?i)\h*.*\Q" & $remove & "\E.*\v","")Spot on mate.Thanks a lot.
60aside Posted April 21, 2010 Author Posted April 21, 2010 I have found that I have some duplicate entries in $text. Is there a way to remove these and just keep the 1st entry? A quick search comes up with _ArrayUnique, is this the way to go with this? Thanks again.
MrMitchell Posted April 22, 2010 Posted April 22, 2010 I have found that I have some duplicate entries in $text.Is there a way to remove these and just keep the 1st entry?A quick search comes up with _ArrayUnique, is this the way to go with this?Thanks again.Others could probably chime in and provide better suggestions, but if there are duplicate lines then you may be able to use _ArrayUnique(), but you need the whole $text into an array first. Then the new array would have be output element-by-element to a new file to get back to where you started. This might not even be feasible depending on how big the $text is...
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