Advertisement
vkz

ms.rkt - Racket scripting

vkz
Jul 20th, 2013
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.76 KB | None | 0 0
  1. #! /usr/bin/env racket
  2. #lang racket
  3.  
  4. (define files
  5.   (filter
  6.    (lambda (e) (regexp-match? #rx"[^-ms]\\.csv" e))
  7.    (directory-list (current-directory))))
  8.  
  9. ;; (stdin stdout) now point to (in out)
  10. (define (with-in-out-files proc in out)
  11.   (with-input-from-file in
  12.     (lambda ()
  13.       (with-output-to-file out proc  #:mode 'text #:exists 'replace))))
  14.  
  15. (define (replace-dot-in-file in)
  16.   (define (dot->comma)
  17.     (for ([l (in-lines)])
  18.       (printf "~a\n"   (regexp-replace #rx"\\." l ","))))
  19.   (define (out-filename file suffix)
  20.     (define file-ext  (regexp-split #rx"\\." file))
  21.     (string-append (first file-ext) suffix "." (second file-ext)))
  22.   (with-in-out-files dot->comma in (out-filename in "-ms")))
  23.  
  24. (time (for-each replace-dot-in-file files))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement