Jump to content

Remove Duplicate lines through RegExp


Recommended Posts

Something problem from mount...What's wrong with this code?

Thanks so much :lol:

#include <Array.au3>
#include <File.au3>
Dim $aArray
$opentxt = FileOpenDialog('Choose TXT', @DesktopDir, '(*.txt)', 1, '')
$aRegExp = StringRegExp(FileRead($opentxt), "[0-9]{6,12}", 3)
$startmount = Ubound($aRegExp) ;<<<<<Maybe get wrong from here
_FileReadToArray($opentxt, $aArray)
_ArrayDelete($aArray, 0)
$newfile = _ArrayUnique($aArray)
$outputtxt = FileOpen($opentxt, 2)
_FileWriteFromArray($outputtxt, $newfile, 1)
FileClose($opentxt)
$sRegExp = StringRegExp(FileRead($opentxt), "[0-9]{6,12}", 3)
$endmount = Ubound($sRegExp) ;<<<<<And here
MsgBox(0, "Mount", "Before: " &$startmount  &@CRLF &"After: " &$endmount  &@CRLF &"Total Deplicate: " &($startmount - $endmount))

Elson :)

Link to comment
Share on other sites

Does this help?

#include <Array.au3>

Local $File = "First Line" & @CR & "Second Line" & @CRLF & "first line"
Local $aRegEx = StringRegExp( $File, '[^\v]+', 3 )
If @error Then Exit -1 ;No matches

_ArrayDisplay( $aRegEx )
$aRegEx = _ArrayUnique( $aRegEx )
_ArrayDelete( $aRegEx, 0 )
_ArrayDisplay( $aRegEx )

Note that the code will terminate any null character at the SOL/EOF

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

you used [0-9]{6,12} as the pattern

I dont know the condition and what are you trying to achieve

"Before:" should :13

"After:" should :7

"Total Deplicate:" should :6

But it appeared

Before : 25

After: 13

total:12

What do these mean ?

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

By the way, how to get the string infront of "," ?

-----------------------------------

8598437769,h1234567

1339236010,h1234567

157412635,h1234567

2310790863,h1234567yu

176887898,h1fefee4

1050122245,h1234567

2867246473,lPX3hR1

-----------------------------------

like>

8598437769

1339236010

157412635

2310790863

176887898

1050122245

2867246473

:)

Link to comment
Share on other sites

$aArray = StringSplit('8598437769,h1234567|1339236010,h1234567|157412635,h1234567|2310790863,h1234567yu|176887898,h1fefee4|1050122245,h1234567|2867246473,lPX3hR1', "|")
For $I = 1 To $aArray[0]
     $String = StringLeft($aArray[$I], StringInStr($aArray[$I], ",") - 1)
     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $String = ' & $String & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
Next

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

With the spirit of Regex

;Im assuming the chars required are digits if not use . in place of \d

#include <Array.au3>

$String = "8598437769,h1234567" & @CRLF & _
"1339236010,h1234567" & @CRLF & _
"157412635,h1234567" & @CRLF & _
"2310790863,h1234567" & @CRLF & _
"1768878978,h1234567" & @CRLF & _
"1050122245,h1234567" & @CRLF & _
"2867246473,lPX3hR1" & @CRLF & _
"2310790863,h1234567" & @CRLF & _
"1768878978,h1234567" & @CRLF & _
"1050122245,h1234567" & @CRLF & _
"2867246473,lPX3hR1" & @CRLF & _
"2310790863,h1234567" & @CRLF & _
"1768878978,h1234567" & @CRLF & _
"1050122245,h1234567" & @CRLF & _
"2867246473,lPX3hR1"

;Make the Array
$String = StringRegExp( $String, "\d+(?=,)", 3)
If @error Then Exit -1 ;No Match
$String = _ArrayUnique( $String )
_ArrayDelete( $String, 0 )
_ArrayDisplay( $String )

Hope this helps :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Why use _ArrayUnique?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Why use _ArrayUnique?

I got a PM with the requirements stated to remove the duplicated values

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

I got a PM with the requirements stated to remove the duplicated values

Ahh, another case of someone moving the goal posts mid-game. :)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...