多个文件取第一个单词去重后合并
Last active
April 11, 2018 05:39
-
-
Save BUNotesAI/e1308b85b060271ce490c75a2e802f08 to your computer and use it in GitHub Desktop.
多个文件取第一个单词去重后合并
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment