-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.txt
43 lines (33 loc) · 1.06 KB
/
test.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(ns Grep.core
(:import (java.io BufferedReader FileReader))
)
(defn search-line [line search-pattern line-num]
(let [matcher (re-matcher (re-pattern search-pattern) line)
results (hash-map line-num (list) :found 0)]
(loop [matched (re-find matcher)
res results
acc 0]
(if (not (nil? matched))
(do
(let [new-results (assoc results line-num (list (.start matcher) (.end matcher)) :found acc)]
(recur (re-find matcher) new-results (inc acc))
)
)
results
)
)
)
)
;; grep simply scan the given fine and search for the specified reg-ex
;; It returns a list of couples [col row] where each matching has been found
(defn grep [filename search-for]
(let [line-num 0]
(with-open [rdr (BufferedReader. (FileReader. filename))]
(doseq [line (line-seq rdr)]
(println (search-line line search-for (inc line-num)))
)
)
)
)
(grep "c:/emacs-23.4/test.txt" "let")
This is a let test for the command let