AHK to search for file contents? Like Grep

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omar
Posts: 540
Joined: 22 Oct 2015, 17:56

AHK to search for file contents? Like Grep

Post by omar » 07 Dec 2022, 07:47

I need to search file contents. 99% of the time CSV files.

Windows explorer has a setting when searching that allows you to search file contents.
This is great. Except it doesn't always work.

I've used Grep in the past. That was a long time ago.
I don't actually want to install Grep.
But then just wondering if I could use AHK to do what Grep does?

How efficient would it be?
In my folders, I'd have say 10,000 CSV files - all less than 10kb.

Or should I think of using Python instead?

Thanks.

RussF
Posts: 1269
Joined: 05 Aug 2021, 06:36

Re: AHK to search for file contents? Like Grep

Post by RussF » 07 Dec 2022, 08:19

Not an AHK solution, but I've had good results with SearchMyFiles from NirSoft.

Russ

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK to search for file contents? Like Grep

Post by mikeyww » 07 Dec 2022, 09:06

Total Commander and lots of other programs can also search files on the fly. If you want something very fast, you'd probably need a program that indexes your files. There are lots of those, too, like dtSearch. That said, small CSV files could be read very quickly by just about any program, including AHK. You could also write a script that indexes your files and then retrieves them quickly.

omar
Posts: 540
Joined: 22 Oct 2015, 17:56

Re: AHK to search for file contents? Like Grep

Post by omar » 07 Dec 2022, 09:27

SearchMyFiles looks good.
Looks like ancient Windows interface - but if it does the job, great
Very small

File indexing?
Hmmm... how much overhead does that use up?
I'd consider if no real impact on my laptop
Let me know
Thanks

In anycase... AHK solution maybe would not be good...
I need a GUI interface to open files after searches!

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK to search for file contents? Like Grep

Post by mikeyww » 07 Dec 2022, 11:07

I use dtSearch to index my entire computer (updated document files only) every night. I have no idea how much overhead it uses, because I'm always asleep when it's doing the work. :)

garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: AHK to search for file contents? Like Grep

Post by garry » 07 Dec 2022, 11:40

search for files > Everything
https://www.voidtools.com/

search for files / words in file > XSearch
https://www.easexp.com/xsearch/

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK to search for file contents? Like Grep

Post by mikeyww » 07 Dec 2022, 12:02

The technique of choice (e.g., indexing or not) depends on the situation: how often searches are done, the scope of a typical search, and the extent to which search time matters. Infrequent searches of smaller scope or smaller files may not benefit much from indexing, compared to larger or more frequent searches. I use both techniques together: Total Commander for my narrow and smaller searches, and dtSearch when I need to search hundreds or thousands of long documents at once. An advanced program like dtSearch has some additional features: can search for synonyms, misspellings, dates and numbers in certain ways, words near other specific words, plurals or stemming, and even words that sound similar.

garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: AHK to search for file contents? Like Grep

Post by garry » 07 Dec 2022, 16:46

dtsearch seems professional

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: AHK to search for file contents? Like Grep

Post by flyingDman » 07 Dec 2022, 17:14

I am often surprised about AHK's file-reading speed. So I tested this. I made a folder with 10,000 csv files, each consisting of random words (from a 280k wordlist) . 100 rows and 10 columns. Each file is about 10K. Then, with a simple loop and using instr to search, I searched through each file. The results are impressive again. About 500 ms to search all occurrences of the search term. AHK is highly capable to do this.
Search script:

Code: Select all

st := A_TickCount
loop, 10000
	{
	fileread, oVar, %a_scriptdir%\csvfolder\csv%a_index%.csv
	if (instr(oVar,"fast"))								; change the search term here
		lst .= a_scriptdir "\csvfolder\csv" a_index ".csv`n"
	}
msgbox % a_tickcount - st "`n`n" lst
Make 10,000 csv files (this takes about 30 minutes on my PC):

Code: Select all

fileread, var, C:\Users\xxx\Scripts\Wordlist_280K.txt
arr := strsplit(var,"`n","`r")
loop, 10000
	{
	i := a_index
	loop, 1000
		{
		random, rndm, 1, 280000
		fileappend, % mod(a_index,10) = 0 ? arr[rndm] "`n" : arr[rndm] ",", %a_scriptdir%\csvfolder\csv%i%.csv
		}
	}
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”