Need help removing duplicate lines

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Need help removing duplicate lines

23 Jan 2024, 23:14

I need to elimiate all lines with duplicate OutputArray5, the rest of the line does not matter.
It does not matter which line it deletes that have a matching OutputArray5

In this example it does not matter which of these 2 it removes, because OutputArray5 (MIN100) is an exact match.
Vases*S/10 Hinged Flower Vase*$82.50*In Stock*MIN100*ShelfA
or
Flowers*S/10 Hinged Flower Vase*$82.50*In Stock*MIN100*ShelfA

My code is incorrect because it finds MIN100 in lines that contain MIN100-LG,MIN100-SM,MIN100-MD and MIN100-SIL and therefore treats them as duplicates.

Code: Select all

var =
(
Decor*12" Large Glass Vial*$2.25*In Stock*MIN100-LG*ShelfA
Bowls*12" Pedestal Bowl*$75.00*Out of Stock*CQU025*ShelfA
Decor*6" Small Glass Vial*$1.75*In Stock*MIN100-SM*ShelfA
Flowers*S/10 Hinged Flower Vase*$82.50*In Stock*MIN100*ShelfA
Glass*8" Medium Glass  Vial*$2.00*In Stock*MIN100-MD*ShelfA
Vases*S/10 Hinged Flower Vase*$82.50*In Stock*MIN100*ShelfA
Vases*Japanese Flower Blossoms Vase*$150.00*In Stock*DRU255*ShelfA
Vases*Lavoisier Set of 10 Hinged Flower Vases*$82.50*In Stock*MIN100-SIL*ShelfA
Decor*S/2 Amazonite Boxes*$55.00*In Stock*HCM008-AMS2*ShelfA
)
	
Loop, Parse, Var, `n
 {
  StringReplace, outputvar, A_LoopField,`r`n,,All 
  StringSplit,OutputArray,Outputvar,*
  IfNotInString, NoDuplicates, %OutputArray5%
   {
    if NoDuplicates =
 	 NoDuplicates = %a_loopfield%
    else
     NoDuplicates := (NoDuplicates a_loopfield "`n" )
   }
 }
msgbox,,Ahk %a_linenumber%, % NoDuplicates
;NoDuplicates is missing both lines that contain MIN100 as OutputArray5
;Flowers*S/10 Hinged Flower Vase*$82.50*In Stock*MIN100*ShelfA
;Vases*S/10 Hinged Flower Vase*$82.50*In Stock*MIN100*ShelfA
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
mikeyww
Posts: 27197
Joined: 09 Sep 2014, 18:38

Re: Need help removing duplicate lines

23 Jan 2024, 23:25

Instead of seeing whether your string contains text, see whether it contains *text*.
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Re: Need help removing duplicate lines

23 Jan 2024, 23:33

mikeyww wrote:
23 Jan 2024, 23:25
Instead of seeing whether your string contains text, see whether it contains *text*.
Good suggestion. I am working on that now.
thanks
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Re: Need help removing duplicate lines

23 Jan 2024, 23:36

mikeyww wrote:
23 Jan 2024, 23:25
Instead of seeing whether your string contains text, see whether it contains *text*.
I would have spent hours and come up with a complicated solution, when all I had to do was change

Code: Select all

IfNotInString, NoDuplicates, %OutputArray5%
to

Code: Select all

IfNotInString, NoDuplicates, *%OutputArray5%*
thanks again
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Re: Need help removing duplicate lines

23 Jan 2024, 23:39

mikeyww wrote:
23 Jan 2024, 23:25
Instead of seeing whether your string contains text, see whether it contains *text*.
Let me ask you something else.

I do this alot, and I mean alot. Seems like there would be a better way to avoid a blank line at the beginning of a variable

Code: Select all

    if NoDuplicates =
 	 NoDuplicates = %a_loopfield%
    else
     NoDuplicates := (NoDuplicates a_loopfield "`n" )
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
mikeyww
Posts: 27197
Joined: 09 Sep 2014, 18:38

Re: Need help removing duplicate lines

23 Jan 2024, 23:43

Code: Select all

#Requires AutoHotkey v1.1.33
txt = 
(
Decor*12" Large Glass Vial*$2.25*In Stock*MIN100-LG*ShelfA
Bowls*12" Pedestal Bowl*$75.00*Out of Stock*CQU025*ShelfA
Decor*6" Small Glass Vial*$1.75*In Stock*MIN100-SM*ShelfA
Flowers*S/10 Hinged Flower Vase*$82.50*In Stock*MIN100*ShelfA
Glass*8" Medium Glass  Vial*$2.00*In Stock*MIN100-MD*ShelfA
Vases*S/10 Hinged Flower Vase*$82.50*In Stock*MIN100*ShelfA
Vases*Japanese Flower Blossoms Vase*$150.00*In Stock*DRU255*ShelfA
Vases*Lavoisier Set of 10 Hinged Flower Vases*$82.50*In Stock*MIN100-SIL*ShelfA
Decor*S/2 Amazonite Boxes*$55.00*In Stock*HCM008-AMS2*ShelfA
)
Loop Parse, txt, `n, `r
 noDupes .= InStr(noDupes, "*" StrSplit(A_LoopField, "*")[5] "*") ? ""
          : (noDupes = "" ? "" : "`n") A_LoopField
MsgBox 0, Result, % noDupes
Or just Trim() when done.
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Re: Need help removing duplicate lines

24 Jan 2024, 00:16

Code: Select all

Loop Parse, txt, `n, `r
 noDupes .= InStr(noDupes, "*" StrSplit(A_LoopField, "*")[5] "*") ? ""
          : (noDupes = "" ? "" : "`n") A_LoopField
MsgBox 0, Result, % noDupes
Now, that is some nifty code. It works great. I am going to study how that works.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
mikeyww
Posts: 27197
Joined: 09 Sep 2014, 18:38

Re: Need help removing duplicate lines

24 Jan 2024, 07:25

Sounds good. This removes the deprecated commands and uses the corresponding functions. It also uses, twice, the ternary operator, like "If... then... else" for expressions, as described in the documentation. For each line, if the target string is found, nothing is appended to the output string; otherwise, the line is appended. If the output string was already populated, then the line is preceded by a line feed.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 125 guests