was strange I didn't see lines if they contain the 2 characters ( , ) e.g. ( Date: Fri, Jan 3, 2020 at 11:59 AM and CC: ... , , )
EDIT : example was wrong , removed .
;- script modified in case1 , because I didn't found these if use file :
;Date: Fri, Jan 3, 2020 at 11:00 AM
;Date: Fri, Jan 3, 2020 at 11:58 AM
;Cc: kelly_DeSilvaGroup.com <kelly_ajogroup.com>, , Bill
EDIT : tried this :
Code: Select all
;-------- saved at 2022-05-19 08:07 UTC --------------
;- How to Remove Duplicate Lines from a File - Page 2
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=104148&start=20
;- example to remove double lines
;-
;- script modified in case1 , because I didn't found these if use file :
;Date: Fri, Jan 3, 2020 at 11:00 AM
;Date: Fri, Jan 3, 2020 at 11:58 AM
;Cc: [email protected] <[email protected]>, , Bill
;-
#MaxMem 4095
transform,s,chr,32
transform,v,chr,127
;-
;-----------
goto,case1 ;-- case1=readfile / case2=test
;-----------
;-
case1:
F1:=a_scriptdir "\sampletext2.txt" ;- this source-text and this ahk-script is saved in notepad as 'UTF-8 with BOM'
F2:=a_scriptdir "\" . a_now . "_sampletext2_new.txt"
Out:=""
Obj := FileOpen(F1, "r",UTF-8)
var := Obj.Read()
stringreplace,var,var,`,,%s%%v%,all
Obj.Close()
;------
Loop,parse,var,`n,`r
{
x:= A_LoopField
x=%x%
if x=
continue
If out not contains %x%
out .= x . "`r`n"
}
stringreplace,out,out,%s%%v%,`,,all
;------
ifnotexist,%f2%
{
FileOpen(F2, "w", "UTF-8").Write(out)
try
run,%f2%
}
out=
x=
exitapp
;---------------------------------------------
esc::exitapp
;---------------------------------------------
;-
case2:
;- example to remove double lines
;-
out:=""
gosub,testtext
Loop,parse,var,`n,`r
{
x:= A_LoopField
x=%x%
if x=
continue
If out not contains %x%
out .= x . "`r`n"
}
msgbox,%out%
out=
x=
exitapp
;================
;----------------
testtext:
var=
(
From: Joe Smith <[email protected]>
Date: Fri, Jan 3, 2020 at 11:59 AM
Subject: Re: PJ160605 237 23rd Ave - site visit
To: Bob <[email protected]>
Cc: [email protected] <[email protected]>, , Bill
Dear Joe,
Yes, I will meet you Friday.
Sincerely me,
Sincerely me,
Bob1 line
Dear Joe,
I will never do business with you.
Regards you,
Regards you,
Bob2 line
)
return
;============================================================================
Code: Select all
;- modified = 20220520
;- example try to remove doublelines and convertdatetime
;-
#MaxMem 4095
transform,s,chr,32
transform,v,chr,127
;-
F2:=a_desktop . "\" . a_now . "_result_text.txt"
out:=""
gosub,testtext
stringreplace,var,var,`,,%s%%v%,all
Loop,parse,var,`n,`r
{
x:= A_LoopField
if x=
continue
x=%x%
If out not contains %x%
{
stringmid,x1,x,1,5
if (x1="Date:") ;- convert 'Date: Fri, Jan 3, 2020 at 11:59 PM' > 20200103235900
{
stringmid,x2,x,6,40
stringreplace,x2,x2,%s%%v%,`,,all
timex:=DateParse(x2)
timex2:=timex . "00"
FormatTime,TS,%timex2% L0x0804, dddd MMMM yyyy-MM-dd HH:mm ;
x:="Date:=" . TS
x1:=""
}
out .= x . "`r`n"
}
}
stringreplace,out,out,%s%%v%,`,,all
ifnotexist,%f2%
{
FileOpen(F2, "w", "UTF-8").Write(out)
try
run,%f2%
}
out=
x=
exitapp
;================
;----------------
testtext:
var:="
(Ltrim join`r`n
From: Joe Smith <[email protected]>
---------------
Date: Fri, Jan 3, 2020 at 11:59 AM
---
Subject: Re: PJ160605 237 23rd Ave - site visit
To: Bob <[email protected]>
Cc: [email protected] <[email protected]>, , Bill
----
Date: Sat, Jan 4, 2020 at 11:59 PM
-----
Dear Joe1,
Yes, I will meet %you Friday.
Dear Joe1,
Sincerely me,
Sincerely me,
Bob1 line
Dear Joe2,
I will never do business with you.
Dear Joe2,
Regards you,
Regards you,
Bob2 line
)"
return
;============================================================================
;time:=DateParse("1/2/2020 9:45 PM") ;- user 'polyethene'
;msgbox,%time%
;return
;- https://www.autohotkey.com/board/topic/18760-date-parser-convert-any-date-format-to-yyyymmddhh24miss/
;-----------------------------------------------------------------------------------------------
DateParse(str, americanOrder=0) {
static monthNames := "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*"
, dayAndMonth := "(?:(\d{1,2}|" . monthNames . ")[\s\.\-\/,]+)?(\d{1,2}|" . monthNames . ")"
If RegExMatch(str, "i)^\s*(?:(\d{4})([\s\-:\/])(\d{1,2})\2(\d{1,2}))?"
. "(?:\s*[T\s](\d{1,2})([\s\-:\/])(\d{1,2})(?:\6(\d{1,2})\s*(?:(Z)|(\+|\-)?"
. "(\d{1,2})\6(\d{1,2})(?:\6(\d{1,2}))?)?)?)?\s*$", i) ;ISO 8601 timestamps
year := i1, month := i3, day := i4, t1 := i5, t2 := i7, t3 := i8
Else If !RegExMatch(str, "^\W*(\d{1,2}+)(\d{2})\W*$", t){
RegExMatch(str, "i)(\d{1,2})" ;hours
. "\s*:\s*(\d{1,2})" ;minutes
. "(?:\s*:\s*(\d{1,2}))?" ;seconds
. "(?:\s*([ap]m))?", t) ;am/pm
StringReplace, str, str, %t%
If Regexmatch(str, "i)(\d{4})[\s\.\-\/,]+" . dayAndMonth, d) ;2004/22/03
year := d1, month := d3, day := d2
Else If Regexmatch(str, "i)" . dayAndMonth . "[\s\.\-\/,]+(\d{2,4})", d) ;22/03/2004 or 22/03/04
year := d3, month := d2, day := d1
If (RegExMatch(day, monthNames) or americanOrder and !RegExMatch(month, monthNames)) ;try to infer day/month order
tmp := month, month := day, day := tmp
}
f = %A_FormatFloat%
SetFormat, Float, 02.0
d := (StrLen(year) == 2 ? "20" . year : (year ? year : A_YYYY))
. ((month := month + 0 ? month : InStr(monthNames, SubStr(month, 1, 3)) // 4 ) > 0 ? month + 0.0 : A_MM)
. ((day += 0.0) ? day : A_DD)
. t1 + (t1 == 12 ? t4 = "am" ? -12.0 : 0.0 : t4 = "pm" ? 12.0 : 0.0)
. t2 + 0.0 . t3 + 0.0
SetFormat, Float, %f%
return, d
}
;-------------------------------------------------------------------------------------------
/*
Function: DateParse
Converts almost any date format to a YYYYMMDDHH24MISS value.
Parameters:
str - a date/time stamp as a string
Returns:
A valid YYYYMMDDHH24MISS value which can be used by FormatTime, EnvAdd and other time commands.
Example:
time := DateParse("2:35 PM, 27 November, 2007")
License:
- Version 1.05 <http://www.autohotkey.net/~polyethene/#dateparse>
- Dedicated to the public domain (CC0 1.0) <http://creativecommons.org/publicdomain/zero/1.0/>
*/
;============================================================================================