多个文件取第一个单词去重后合并
(ns alexcoding.sandbox.appendnumforfile)
(require '[clojure.string :as str])
(def allwords (atom []))
;; 读取文件到allwords里
(with-open [r (clojure.java.io/reader "/tmp/5.txt")]
(doseq [line (line-seq r)]
(swap! allwords conj (str/join "" (take 1 (str/split line #"\t"))))))
(println (count @allwords))
;; 合并到output
(with-open [w (clojure.java.io/writer "/tmp/output.txt" :append true)]
(doseq [line @allwords]
(.write w line)
(.newLine w)))