Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: import a CSV into org-mode

Emacs has a very nice extension by the name of org-mode.

I would like to be able to easily load CSV files into org-mode without significant grief. All I've been able to find is table-import or table-capture, which, simply put, don't work even approximately well.

Note that part of my issue is text strings with a comma within them. 1,2,3,4 is different than 1,2,"3,4".

Is there a function out there or a perl script that one could run to transform a csv file into org-mode format?

Thanks!

like image 534
Paul Nathan Avatar asked Aug 06 '09 21:08

Paul Nathan


1 Answers

From the org-mode manual:

C-c | Convert the active region to table. If every line contains at least one TAB character, the function assumes that the material is tab separated. If every line contains a comma, comma-separated values (CSV) are assumed. If not, lines are split at whitespace into fields. You can use a prefix argument to force a specific separator: C-u forces CSV, C-u C-u forces TAB, and a numeric argument N indicates that at least N consecutive spaces, or alternatively a TAB will be the separator. If there is no active region, this command creates an empty Org table.

So just paste the data into an org file, select it, and do C-u C-c | .

like image 101
Don Womick Avatar answered Sep 23 '22 18:09

Don Womick