<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi. I thought I'd use Racket to solve a silly little scripting problem.&nbsp;<div><br></div><div>Script doesn't take arguments, instead looks for .csv files in its directory, reads them line by line, does some trivial replacement and writes the result to a new .csv file adding "-ms" suffix to its name. You can see my solution&nbsp;<a href="http://pastebin.com/CPb5gxEu">http://pastebin.com/CPb5gxEu</a>&nbsp;and below. I suppose you bearded hackers would roll-out a quick awk + sh script in a minute - seems like exactly the task suited for awk. Unfortunately I find I'm allergic to sh - entirely too much of a challenge for me. Plus .csv files I'm dealing with are on the order of &gt;200Mb.&nbsp;<br><br>Writing it felt somewhat awkward or rather more so than I anticipated, hence this post. Can you see a better, more straightforward, canonical way of doing this sort of things? Feels like general-purpousness of the language shows and a dsl like scsh would allow more straightforward style. &nbsp;<div><br><div><div>#! /usr/bin/env racket</div><div>#lang racket</div><div><br></div><div>;; doesn't tell directories and files apart, can be dangerous</div><div>(define files</div><div>&nbsp; (filter</div><div>&nbsp; &nbsp;(lambda (e) (regexp-match? #rx"[^-ms]\\.csv" e))</div><div>&nbsp; &nbsp;(directory-list (current-directory))))</div><div><br></div><div>;; this really should be a straightforward pipe with processing in the middle</div><div>;; this wrapping of with--file procedures feels a little like writing cps by hand</div><div>;; (stdin stdout) now point to (in out)</div><div>(define (with-in-out-files proc in out)</div><div>&nbsp; (with-input-from-file in</div><div>&nbsp; &nbsp; (lambda ()</div><div>&nbsp; &nbsp; &nbsp; (with-output-to-file out proc &nbsp;#:mode 'text #:exists 'replace))))</div><div><br></div><div>(define (replace-dot-in-file in)</div><div>&nbsp; (define (dot-&gt;comma)</div><div>&nbsp; &nbsp; (for ([l (in-lines)])</div><div>&nbsp; &nbsp; &nbsp; (printf "~a\n" &nbsp; (regexp-replace #rx"\\." l ","))))</div><div>&nbsp; (define (out-filename file suffix)</div><div>&nbsp; &nbsp; (define file-ext &nbsp;(regexp-split #rx"\\." file))</div><div>&nbsp; &nbsp; (string-append (first file-ext) suffix "." (second file-ext)))</div><div>&nbsp; (with-in-out-files dot-&gt;comma in (out-filename in "-ms")))</div><div><br></div><div>;; good candidate to exploit that multi-core bazooka</div><div>;; should I be using futures / places / threads and&nbsp;</div><div>;; some kind of parallel map here?&nbsp;</div><div>(time (for-each replace-dot-in-file files))</div><div><br></div><div>Thanks</div><div><br></div><div><br></div><div><br></div></div></div></div></body></html>