well you might look at /loadbuf
/loadbuf [lines] [-pirsgleopcnmNt<topic>] <window | dialog id> <filename>
Loads the specified number of lines from the end of the file of filename into the specified window.
/loadbuf 20 @test info.txt
This loads the last 20 lines of info.txt into custom window @test.
in the help for /filter
This command also fills the $filtered identifier with the number of matches found, if any.
$filtered
Returns the number of lines that were filtered when using the /filter command.
so you can use something like:
if ($filtered == $null) to retun something if no matches were found
if (!$filtered) { write filter_search.txt No Matches Found }
instead of the while loop, look at using play
or loadbuf savebuf I think will do what you want.