help me please

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

help me please

13 Apr 2020, 15:39

Hello guys, I would like some help

I want to open a file that always updates once opened. I want you to look for a word from the bottom up when you find it. I want a message to appear on the screen saying that you found it.

with a button to activate each time I press it opens the file and searches for the word
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

Re: help me please

13 Apr 2020, 16:44

f::
Run, open "C:\Users\computer\Desktop\ID.txt"
Send, {LControl Down}{End}{LControl Up}
seach for text up ----------- I don't know what would be here. in fact, there are several words, I want him to notify me what was the first word he found always looking up
the words to search for example (123,321,541,741)
MsgBox,text that was found
Sleep, 1000
exit block of text
Last edited by legyster on 13 Apr 2020, 17:18, edited 1 time in total.
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: help me please

13 Apr 2020, 17:18

Hello and welcome,

How about something like this:

Code: Select all

F2::
FileRead, Clipboard, C:\Users\USER\Documents\AHK\example.txt
searchWordArray := ["hello", bye"] ; Array of words to search for
for i, searchWord in searchWordArray ; Cycle through array
{
  if Clipboard contains %searchWord% ; If any searchword was found:
  {
    MsgBox, ALERT! %searchWord% ; Action
  }
}
return
?

Probably you don't have to open the file, so just try that way.


Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

Re: help me please

13 Apr 2020, 17:22

the text file keeps being updated, so I would have to look from the bottom up and see which was the last one to be typed
I want a message for each of the words to find
it is mandatory to read from the bottom up
whenever I press the button, it should read the file and look for one of the words from the bottom up and notify which one was found first on the screen
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

Re: help me please

13 Apr 2020, 17:46

it is possible to read a file from the bottom up
simusphere
Posts: 18
Joined: 05 Apr 2020, 20:40

Re: help me please

13 Apr 2020, 17:54

I would use Perl if your going to parse a large text file. You did not say how big the file was that is constantly updating (logfile). After you trigger a hotkey in AHK, you would necessarily have to take a snapshot of the file at that given point in time. Then reverse it and search for the word normally from the top down. You could then use the script already suggested above.

If you install Perl on your system, you could use this to do the file reversing and then use the reversed file to search for your word from top down.

Code: Select all

perl -e "print reverse <>" file > file_reversed
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

Re: help me please

13 Apr 2020, 18:02

reverse would be before reading the words is not
eu não entendo nada sobre autohotkey, estou apenas tentando fazer esse script
with help i will succeed :thumbup:
simusphere
Posts: 18
Joined: 05 Apr 2020, 20:40

Re: help me please

13 Apr 2020, 18:14

Usually with AHK automation of some kind, you kind of have to know how to do something manually first. Then with AHK script, you could automate it. So how would search for a word in a file from the bottom up manually? Think about it.
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

Re: help me please

13 Apr 2020, 18:27

you would read the file without opening it, press ctrl-end-ctrl-f would put an up arrow and put the word to be searched and press the Enter button a loop until you find it. I only know basic things.

I'm close?
simusphere
Posts: 18
Joined: 05 Apr 2020, 20:40

Re: help me please

13 Apr 2020, 18:55

No, that's not what I meant. You're thinking in programming lingo. Without any program, how would search for a word in a file after opening it from the bottom of the file? I know a few other programming languages and I wouldn't use AHK to do what your trying to do. That's why I suggested Perl. But you could use AHK script to launch the perl script. I would just do everything in perl and possibly launch the perl script from AHK. The one line of code to do the reversing is easy as I have already shown. Then you could simply do the search using Perl but I don't want to get too out of focus of what this forum is about.
User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: help me please

13 Apr 2020, 19:01

This will parse the file's content line by line in reverse order. If matches occur they will pop up in reverse order (last one first):

Code: Select all

var = 
(
KP64745
XG60754
easter egg
KO44392
YA42966
RS15115
UI14017
KI71466
easter egg
MC18131
EQ97720
)								; this simulates reading a text file

arr := strsplit(var, "`n", "`r")
loop, % ln := arr.length()
	if (arr[ln - a_index + 1] = "easter egg")
		msgbox % "found at row " ln - a_index + 1

14.3 & 1.3.7
User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: help me please

13 Apr 2020, 19:41

Or use sort to reverse the order of the list (see last example in the help file):

Code: Select all

Sort, var, F ReverseDirection D`n  						; Reverses the list 

for x,y in arr := strsplit(var, "`n", "`r")
	if (y = "easter egg")
		msgbox % "found at row " arr.length() - x + 1

ReverseDirection(a1, a2, offset)
	{
    return offset  										; Offset is positive if a2 came after a1 in the original list, negative otherwise
	}
14.3 & 1.3.7
simusphere
Posts: 18
Joined: 05 Apr 2020, 20:40

Re: help me please

13 Apr 2020, 21:32

FlyingDman, I suppose that answers the OP's question as it was asked but I'm guessing he wanted to see each line that was found based on a substring search. Guess we'll have to wait till he comes back with a comment on it. I did test it with an actual log file and your code works pretty good. I just changed it slightly.

Code: Select all

^l::
FileRead, var, G:\path\to\file\Sample.log

arr := strsplit(var, "`n", "`r")
msgbox % arr.length() " lines in log file"
loop, % ln := arr.length()
	if instr(arr[ln - a_index + 1], "826")
		msgbox % arr[ln - a_index + 1]
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

Re: help me please

14 Apr 2020, 00:30

the log file must be read from the bottom up when it finds one of the 10 words, it must stop and inform which one was found first whenever I press the button informs which word appears first.

the words come in totally random order
simusphere
Posts: 18
Joined: 05 Apr 2020, 20:40

Re: help me please

14 Apr 2020, 06:20

the words come in totally random order
If you want multiple search values, that will require more work. Plus, what do you mean, the words come in random order? You have to know what your searching for to find it. The following handles the case of exactly one search term.

And FlyingDmans code does that, except didn't show the line found. I made a few changes in his code and it does exactly what you are asking. Did you try it? To make it perfectly clear, I'll put a variable called SearchVal at the top of the script and you can put whatever string you are looking for in that variable (one substring). My testing shows that it tests every line from the file starting from the bottom and will show you the line it found in a msgbox. If you press OK, it starts going further up the file looking for another occurrence of SearchVal and displaying that if it finds one. Also, you never mentioned how big a log file you are dealing with.

Code: Select all

; Searches a logfile called Sample.log from the bottom up finding all occurrences of SearchVal
^l::
SearchVal:="9826"
FileRead, var, G:\E2P\Programs\AutoHotKey\Sample.log
arr := strsplit(var, "`n", "`r")
msgbox % "Looking for " SearchVal " in logfile with " arr.length() " lines."
loop, % ln := arr.length()
	if % instr(arr[ln - a_index + 1], SearchVal)
		msgbox % arr[ln - a_index + 1]
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: help me please

14 Apr 2020, 06:42

legyster, have you actually tried my script and can confirm that this method does not work?
Of course you can put a loop around it, so that it checks the file continuously.

It seems the file gets updated all the time, so with the loop you will always be up to date.

Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
simusphere
Posts: 18
Joined: 05 Apr 2020, 20:40

Re: help me please

14 Apr 2020, 11:03

Let's see if this works for ya. Just replace the SearchVal variables with your 10 custom strings. This will search from the bottom of the file for the first of any of the 10 search values. The first one it finds, it will display in a msgbox along with the value it found.

Code: Select all

; Searches a logfile called Sample.log from the bottom up finding all occurences of SearchVar01-10
^l::
SearchVal01:="1507"
SearchVal02:="8561"
SearchVal03:="3376"
SearchVal04:="8799"
SearchVal05:="1989"
SearchVal06:="1542"
SearchVal07:="2650"
SearchVal08:="1392"
SearchVal09:="9096"
SearchVal10:="1414"
FileRead, var, C:\path\to\file\sample.log
arr := strsplit(var, "`n", "`r")
msgbox % "Looking for " SearchVal01 " in logfile with " arr.length() " lines."
loop, % ln := arr.length() {
	;msgbox % ln - a_index + 1
	currln := arr[ln - a_index + 1]
	;msgbox % currln "_MIKE"
	if % instr(currln, SearchVal01)
		msgbox % currln "Found " SearchVal01
	else if % instr(currln, SearchVal02)
		msgbox % currln "Found " SearchVal02
	else if % instr(currln, SearchVal03)
		msgbox % currln "Found " SearchVal03
	else if % instr(currln, SearchVal04)
		msgbox % currln "Found " SearchVal04
	else if % instr(currln, SearchVal05)
		msgbox % currln "Found " SearchVal05
	else if % instr(currln, SearchVal06)
		msgbox % currln "Found " SearchVal06
	else if % instr(currln, SearchVal07)
		msgbox % currln "Found " SearchVal07
	else if % instr(currln, SearchVal08)
		msgbox % currln "Found " SearchVal08
	else if % instr(currln, SearchVal09)
		msgbox % currln "Found " SearchVal09
	else if % instr(currln, SearchVal10)
		msgbox % currln "Found " SearchVal10
	;sleep 40
}
msgbox Finished Searching Entire File.
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

Re: me ajude por favor

14 Apr 2020, 14:20

you can put a message in the found text, the found text is too long, example 154548787878 = 1
I want to make it tiny.
I don't know if it's right anymore, he sends the whole message.
that was exactly what I wanted, now I need to put a name in the word found. It was meant to be (SearchVal01, SearchVal02, SearchVal03).
is not appearing without the text I would like to change the name more I think this is giving error
simusphere
Posts: 18
Joined: 05 Apr 2020, 20:40

Re: help me please

14 Apr 2020, 17:49

So you don't want to see the whole line of text where the search word is found??? In that case, what do you want to see then.
I have no idea what "example 154548787878 = 1" is supposed to mean.
I want to make it tiny.
You want to make what tiny? do you mean the resulting message that is returned when a match is found?
I don't know if it's right anymore, he sends the whole message.
You know you can change the script to do whatever you what. That's how this works. Learn some of the basics and change it to your requirements.
that was exactly what I wanted, now I need to put a name in the word found. It was meant to be (SearchVal01, SearchVal02, SearchVal03).
You totally lost me on this comment.
is not appearing without the text I would like to change the name more I think this is giving error
Again, if you want to change something, just change it. I highly recommend going through some of the tutorials so you can at least learn some of the basics. Then come back and modify or write your own code to do exactly what you want to do. I'm having trouble understanding what you are trying to do. At first it was just search for a word in a file from the bottom up. Then you added in the 10 search words. Now I have to guess what IT is? I don't know what IT is?

Teach a man to fish and feed him for life. You really need to make an attempt to learn some of the basics first. There a lot of really great tutorials on AKH including the documentation. I learned a great deal from Joe Glines and all the video's he created. He also has a really great Udemy course on the basics to get you started.
legyster
Posts: 106
Joined: 13 Apr 2020, 15:17

Re: help me please

14 Apr 2020, 19:44

sorry, i already solved it, but how do you check this only once
shows everything in order yes but i just want the last word

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hugojans and 100 guests