Skip to content

Instantly share code, notes, and snippets.

@gerritjvv
Created July 9, 2013 09:30
Show Gist options
  • Save gerritjvv/5955996 to your computer and use it in GitHub Desktop.
Save gerritjvv/5955996 to your computer and use it in GitHub Desktop.
Count Frequencies of a column in a tsv file
(def column-n (fn [n sep] (fn [record] (let [s (str record) arr (clojure.string/split s sep)] (arr n)))))
(defn file-freq [file column sep]
(with-open [ rdr (clojure.java.io/reader file) ]
(-> (column-n column sep) (map (line-seq rdr)) frequencies)
)
)
@gokulvanan
Copy link

Interestingly.. i just learnt how to do the same thing using one line cmd in linux today.

cut -d'|' -f | sort | uniq -c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment