cl-grep

Simple implementation of grep
Log | Files | Refs

commit 35b8c35a79855b6191ad4b772431aa82eec541e7
parent 015273a44c07a63c77b8be5854387579961b8d6d
Author: ChanderG <[email protected]>
Date:   Wed,  3 Dec 2025 10:20:16 +0530

consolidate results printing per file

Diffstat:
Mgrep.lisp | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/grep.lisp b/grep.lisp @@ -10,10 +10,16 @@ (lo "Grepping file: ~a" file) (handler-case (with-open-file (stream file) - (loop for line = (read-line stream nil :eof) - until (eq line :eof) collect - (if (sm:search-bmh8 match-idx line) - (format t "~a: ~a ~%" file line)))) + (let ((results + (loop for line = (read-line stream nil :eof) + until (eq line :eof) + if (sm:search-bmh8 match-idx line) + collect line))) + (when results + (format t "~a: ~%" file) + (loop for l in results do + (format t "~a~%" l)) + (format t "~%")))) (stream-error (stream) (lo "Skipping binary file: ~a" file)) (error (c)