Skip to content

Instantly share code, notes, and snippets.

@unionx
Created July 30, 2012 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unionx/3205410 to your computer and use it in GitHub Desktop.
Save unionx/3205410 to your computer and use it in GitHub Desktop.
read and split file in emacs lisp
#!/usr/local/bin/emacs --script
(defun read-lines (filename)
(with-temp-buffer
(insert-file-contents filename)
(split-string (buffer-string) "\n" t)))
;; test.log
;; 111111,22222222222,3333333333333
;; 2222222222,3333333333,444444444
;; 555555555,222222222,1111111
;; 555555555,2222222,111111111
(dolist (var (read-lines "test.log"))
(print (split-string var "," t)))
;; ("111111" "22222222222" "3333333333333")
;; ("2222222222" "3333333333" "444444444")
;; ("555555555" "222222222" "1111111")
;; ("555555555" "2222222" "111111111")
Copy link

ghost commented Jul 30, 2012

it rocks, but I don't think it was in the right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment