Skip to content

Instantly share code, notes, and snippets.

@kymair
Created July 31, 2012 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kymair/3215761 to your computer and use it in GitHub Desktop.
Save kymair/3215761 to your computer and use it in GitHub Desktop.
Read and write file in Clojure
(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