Created
          November 13, 2020 12:11 
        
      - 
      
- 
        Save wwiill/d50c900e0f2874a130065f525f489e1e to your computer and use it in GitHub Desktop. 
    babashka script to process csv
  
        
  
    
      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
    
  
  
    
  | #!/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