To search for a string in files is a common task in day to day work. Most of the time the grep tool can do it. But sometimes we may want more control of the process. We may want to do it pragmatically.

Start from the basic, the simplest form to match a string in another string can be

(defn find-substr [target needle]
  (.contains target needle)

The target can be any string , it can be read from a file. In Clojure we use slurp to read a file as text

(defn read-file-as-text [file]
  (slurp file)

Usually we want match with case insensitive.

(def to-lower clojure.string/lower-case)
(defn matching-file [file match]
  (find-substr (to-lower (read-file-as-text file)) (to-lower match))

With a little effort we can implement a simple grep tool in Clojure

(defn grep [needle dir]
  (filter #(matching-file (str dir "\\" %) needle) (shell "ls.bat" dir))  

See how to get all files in a directory by using shell command : Executing shell command in Clojure REPL