Word filter

Hi,
I want to build a routine to search all paragraphs for a specific string (lets say ‘Vanilla ice’, with a recurrence of 100 entries)
;D
the problem is I have a lot of large txt-documents and want another approach. My current script sucks to much.

set Mytext to choose file with prompt "find your txt-file" without invisibles
set the_txt to text returned of (display dialog "Enter search-term" default answer žbeer")
set the_f to read file Mytext as text
if the_txt is in the_f then my control_file(the_f, the_ls ,
the_txt)

on control_file(the_f, the_ls, the_txt)
	repeat with i from 1 to count of paragraphs in the_f
		if the_txt is in (paragraph i of the_f) then copy (paragraph i of the_f) to end of the_ls -- the_info
	end repeat
end control_file

if the_ls is not {} then set txt to (choose from list the_ls)

Try this…

property searchTerm : "beer"
property maxNumberOfResults : 100

set Mytext to choose file with prompt "find your txt-file" without invisibles
set searchTerm to text returned of (display dialog "Enter search-term" default answer searchTerm)

try
	set the_ls to paragraphs of (do shell script "cat " & quoted form of POSIX path of Mytext & " | grep -i " & quoted form of searchTerm)
on error
	set the_ls to {}
end try

if the_ls is {} then
	display dialog "Could not find the search term!" & return & return & "Search Term: " & searchTerm & return & "File: " & (POSIX path of Mytext) buttons {"OK"} default button 1 with icon 2
else
	if (count of the_ls) is greater than maxNumberOfResults then set the_ls to items 1 thru maxNumberOfResults of the_ls
	set txt to (choose from list the_ls)
end if

regulus,
thank you much!

Glad to help. :smiley: