Created
July 31, 2012 10:07
-
-
Save kymair/3215761 to your computer and use it in GitHub Desktop.
Read and write file in Clojure
This file contains 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
(use '[clojure.string :only [split]]) | |
(require '[clojure.java.io :as io]) | |
(def format-str "%1$-255s%2$09d%3$-255s%4$-1000s%5$-1s") | |
(defn format-line | |
[line] | |
(let [[v1 v2 v3 v4 v5] (split line #",")] | |
(format format-str v1 (read-string v2) v3 v4 v5))) | |
(defn -main [file] | |
(let [lines (split (slurp file) #"\n")] | |
(with-open [wrt (io/writer (str file ".txt"))] | |
(doseq [line lines] | |
(.write wrt (str (format-line line) "\n")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment