philipbohun.com

Glojure by Example: Line Filters

A line filter reads stdin, transforms each line, and writes stdout. bufio is not exported, so copy stdin into a strings.Builder and split the text.

(require '[clojure.string :as string])

(let [buf (new strings.Builder)]
  (io.Copy buf os.Stdin)
  (doseq [line (string/split-lines (str buf))]
    (println (string/upper-case line))))

Pipe a few lines in. split-lines drops the separators, and println puts them back.

$ printf 'hello\nworld\n' | glj line-filters.glj
HELLO
WORLD

Next example: File Paths.