Need Help with an Idea of an Sorting script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Liaxim
Posts: 35
Joined: 09 Jan 2020, 05:14

Need Help with an Idea of an Sorting script

01 May 2020, 18:53

Hello guys,

I need some help with an Idea which I had today for a Script.. I am very new in this language and wanted to get a starting point for my script...
My Idea is that I have an txt File in a Folder with Website domains. As I start the Program, it should read these and sort them by their ending. For example there should be all gmails in a diffrent txt and all web and aol on diffrent txt files after the script finished..
Hope anyone have an Idea how to accomplish this kind a result..

Best regards

Matthias
adrian88888888
Posts: 84
Joined: 13 Mar 2020, 22:51

Re: Need Help with an Idea of an Sorting script

01 May 2020, 19:18

first learn the command FileRead to make the script to read the .txt probably

the command InStr checks if a string its in a variable(maybe that helps separating the info in the .txt)

also you can inform about expressions and how to use them(if you learn about them you can separate text), joe glines has videos about how to use them and examples like this:
https://www.youtube.com/watch?v=hmx-CGLBVSQ
but in his channel he probably has explains more

and then probably use some kind of loop command to make it check every line separately

and maybe you want to put the text in some place, in some .txt, for that the command FileAppend could help

i'm just sayin what i know
Liaxim
Posts: 35
Joined: 09 Jan 2020, 05:14

Re: Need Help with an Idea of an Sorting script

01 May 2020, 19:27

Hey adrian88888888,

thanks for your answer. I already know some commands like Fileread and InStr but I am confused how to make like a sort system and how to make that the the script will make a sorted output in txt like all .net domain in one .txt file...
Any Ideas how to make Many txt files automatically after the sorting?

best regards

Matthias
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Need Help with an Idea of an Sorting script

02 May 2020, 11:15

Code: Select all

FileRead domains, domains.txt

Files := {}
Loop Parse, % domains, `n, `r
{
	RegExMatch(A_LoopField, "@\K.*", domain)
	
	if !Files.HasKey(domain)
		Files[domain] := FileOpen(domain ".txt", "a")
	
	Files[domain].WriteLine(A_LoopField)
}
assuming domains.txt contains a newline-separated list of email addresses

e:fix logic error, thanks @hd0202
Last edited by swagfag on 03 May 2020, 06:14, edited 1 time in total.
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Need Help with an Idea of an Sorting script

02 May 2020, 11:29

Impressive, swagfag! It took me minutes to understand that I don't understand your code. My feeling tells me that it works. Your coding is always an inspiration!
hd0202
Posts: 183
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Need Help with an Idea of an Sorting script

03 May 2020, 03:21

if you do not want to loose the first website of each domain: :D

Code: Select all

; FileRead domains, domains.txt

Files := {}
Loop Parse, % domains, `n, `r
{
	RegExMatch(A_LoopField, "@\K.*", domain)
	
	if Files.HasKey(domain)
		Files[domain].WriteLine(A_LoopField)
	else
	{
		Files[domain] := FileOpen(domain ".txt", "a")
		Files[domain].WriteLine(A_LoopField)
	}
}
Hubert

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: balawi28, Google [Bot] and 176 guests