From: Joe Bogner <joebogner@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Calling org babel to each row in a table
Date: Sun, 30 Jun 2013 11:25:22 -0400 [thread overview]
Message-ID: <CAEtzV1byY5U6E7YRvsrnDmWB+pngU2sb-bJj+mDObtFvXZypew@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1342 bytes --]
I often need to transform a table or list of values into a block of text.
For example, if I have a list of 4 files that I want to generate a SQL
script for.
After hunting around, this is the best I came up with:
#+name: table
| File |
| a |
| b |
| c |
| d |
#+name: template
#+begin_src org :results verbatim :var name="abc"
DROP TABLE $name
CREATE TABLE $name (name varchar(100))
BULK INSERT $name FROM '\\1.1.1.1\$name.txt' ...
#+end_src
#+name: apply-template
#+begin_src emacs-lisp :results silent :var table=()
(let (result-table)
(dolist (line (cdr table))
(setq result-table (cons (concat "#+call: template(\"" (car line)
"\") :results raw drawer") result-table)))
(mapconcat 'identity (nreverse result-table) "\n"))
#+end_src
#+call: apply-template(table) :results org :exports both
#+RESULTS: apply-template(table):results org :exports both
#+BEGIN_SRC org
#+END_SRC
Is there a more straightforward method to apply this type of
transformation? Ideally I would skip the emacs-lisp block and use some
syntax to apply a org-babel block for each row in a table.
It sounded similar to this:
http://thread.gmane.org/gmane.emacs.orgmode/69326/focus=69340*, *but that
didn't have a full example for me to build off of
Is there a more straightforward to accomplish this transformation?
Thanks,
Joe
[-- Attachment #2: Type: text/html, Size: 2092 bytes --]
next reply other threads:[~2013-06-30 15:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-30 15:25 Joe Bogner [this message]
2013-06-30 23:33 ` Calling org babel to each row in a table Eric Schulte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAEtzV1byY5U6E7YRvsrnDmWB+pngU2sb-bJj+mDObtFvXZypew@mail.gmail.com \
--to=joebogner@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).