Skip to content

Instantly share code, notes, and snippets.

@wwiill
Created November 13, 2020 12:11
Show Gist options
  • Save wwiill/d50c900e0f2874a130065f525f489e1e to your computer and use it in GitHub Desktop.
Save wwiill/d50c900e0f2874a130065f525f489e1e to your computer and use it in GitHub Desktop.
babashka script to process csv
#!/usr/bin/env bb
;; cat test.csv | csv.clj '(fn [m] (get m "column1"))'
(defn lines->maps [lines]
(let [headers (first lines)
body (rest lines)]
(->> body
(map (partial zipmap headers)))))
(def process (or (some-> *command-line-args*
first
load-string
eval)
identity))
(with-open [reader (io/reader *in*)]
;; bb auto alias clojure.data.csv as csv
(doseq [output (->> (csv/read-csv reader)
(lines->maps)
(map process))]
(println output)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment