I'm trying to write a little Emacs Lisp script that reads a csv file from standard input, turns all the rows into a table then prints it to standard out (Unix). I wrote a basic version that takes a csv string and outputs the table to a buffer. However, I would like to turn this into a Unix utility script.
#!/usr/bin/emacs --script (defun gen-row (lst) (dolist (elm lst) (insert "<tr>") (insert (concat "<td>" elm "</td>")) (insert "</tr>") ) ) (defun parse-csv-line (txt) (setq lst (progn (insert "\n<table>\n") (setq str txt) (gen-row (split-string str ",")) (insert "\n</table>\n") )) ) (parse-csv-line "this,is,a test")
The output to the current buffer when run from within Emacs:
<table> <tr><td>this</td></tr><tr><td>is</td></tr><tr><td>a test</td></tr> </table>
Usage of the script:
./csv2html < foo.csv > bar.html; # emacs --script instead of perl -ane '...'