1

I want to export (not sure if that's the right word) a single column of an org-table as text, with the elements separated by commas. Eg if the table is

| x  | y  |
|----+----|
|  0 |  1 |
|  2 |  3 |
|  4 |  5 |
|  6 |  7 |
|  8 |  9 |

I want to get the result 0,2,4,6,8.

In this case I want the first column, but I'd like a solution that allows me to export any single column.

1

1 Answer 1

2

You can make a function to get the desired column and create a string with all the values. For example:

#+name: tbl
| x  | y  |
|----+----|
|  0 |  1 |
|  2 |  3 |
|  4 |  5 |
|  6 |  7 |
|  8 |  9 |

#+begin_src elisp :var x=tbl col=0
(mapconcat (lambda (r) (number-to-string (nth col r))) x ",")
#+end_src

#+RESULTS:
: 0,2,4,6,8

nth selects the desired column for a row. In order to concatenate all into a string, the number must be converted to a string with number-to-string.

Finally, the above operation is passed to mapconcat, which will form the string with the desired delimiter.

If you don't want the actual table in the exported output, wrap it inside a COMMENT block.

2
  • Neat! So x is bound to the table, as a sequence, but what kind exactly (list of list ?)
    – JeanPierre
    Feb 11, 2017 at 8:30
  • Yes. List of (list or hline)
    – Juancho
    Feb 12, 2017 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.