csv-maker

My Computer Programs 2014.11.18 23:30

Converts text file to CSV file.

 

Arc:

 

(prn "CSV maker")
(pr "File name (.txt): ")
(= in-file-name (readline))
(= out-file-name (string in-file-name ".csv"))
(= in-file (infile in-file-name))
(= out-file (outfile out-file-name))

(= separate-after '(3 5)) ; edit this line

(while (= s (readline in-file))
  (= l (len s))
  (disp "\"" out-file)
  (for i 0 (- l 1)
    (writeb (int (s i)) out-file)   
    (if (find i separate-after) (disp "\",\"" out-file)))
  (disp "\"\n" out-file))

(close out-file)
(close in-file)
(prn "Wrote " out-file-name)



 

newLISP:

(println "CSV maker")
(print "File name (.txt): ")
(define in-file-name (trim (read-line) "\"" "\""))
(define out-file-name (string in-file-name ".csv"))
(define in-file (open in-file-name "r"))
(define out-file (open out-file-name "w"))

(define separate-after '(3 5)) ; edit this line

(while (read-line in-file)
  (define s (current-line))
  (define len (length s))
  (write out-file "\"")
  (for (i 0 (- len 1))
    (write out-file (s i))
    (if (member i separate-after) (write out-file "\",\"")))
  (write-line out-file "\""))

(close out-file)
(close in-file)
(println "Wrote " out-file-name)
(exit)


 

Clojure:

(ns csv-maker.core (:gen-class))
(use '(clojure.java io))

(defn -main [& args]
  (println "CSV maker")
  (print "File name (.txt): ")
  (flush)
  (def in-file-name (read-line))
  (def out-file-name (str in-file-name ".csv"))
  (def separate-after #{3 5}) ; edit this line
  (with-open [in-file (reader in-file-name)
              out-file (writer out-file-name)]   
    (binding [*in* in-file
              *out* out-file]
      (doseq [s (line-seq in-file)]
        (def l (count s))
        (print "\"")
        (dotimes [i l]
          (print (.charAt s i))
          (if (separate-after i) (print "\",\"")))
        (println "\""))))
  (println "Wrote" out-file-name))


 


 

 

신고
Posted by steloflute


Generate bitcoin for me

What's this?