From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: Passing a table to org-babel shell script Date: Sun, 07 Feb 2010 10:20:30 -0700 Message-ID: <87fx5dc68f.fsf@gmail.com> References: <20100124094734.GA10344@cab> <87wryqfc3b.fsf@gmail.com> <20100207090115.GA11136@cab> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NeAoY-0002vl-B1 for emacs-orgmode@gnu.org; Sun, 07 Feb 2010 12:20:54 -0500 Received: from [199.232.76.173] (port=49212 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NeAoX-0002vc-Tu for emacs-orgmode@gnu.org; Sun, 07 Feb 2010 12:20:53 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NeAoX-0005Y0-1X for emacs-orgmode@gnu.org; Sun, 07 Feb 2010 12:20:53 -0500 Received: from mail-px0-f179.google.com ([209.85.216.179]:48095) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NeAoW-0005XS-I0 for emacs-orgmode@gnu.org; Sun, 07 Feb 2010 12:20:52 -0500 Received: by pxi9 with SMTP id 9so5771193pxi.24 for ; Sun, 07 Feb 2010 09:20:51 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matthias Teege Cc: emacs-orgmode@gnu.org Alright, I've set this up so that the table is exported to a comma or tab separated format and then saved as a string to the variable in the source code block. By default tab is used as the separator when exporting the table to a string, but this can be overridden using the :separator header argument. The following large snippet show some example usage of tables in shell scripts. Please let me know how it works for you and if you have any other suggestions. Thanks -- Eric --8<---------------cut here---------------start------------->8--- #+tblname: fibs | 1 | 1 | | 2 | 1 | | 3 | 2 | | 4 | 3 | | 5 | 5 | | 6 | 8 | #+begin_src sh :var table=fibs echo "$table" |wc #+end_src #+results: : 6 12 24 #+begin_src sh :var table=fibs echo "$table" #+end_src #+results: | 1 | 1 | | 2 | 1 | | 3 | 2 | | 4 | 3 | | 5 | 5 | | 6 | 8 | #+begin_src sh :var table=fibs :separator -- echo "$table" | head -1 #+end_src #+results: : 1--1 --8<---------------cut here---------------end--------------->8--- Matthias Teege writes: > On 11:33 Sat 06 Feb, Eric Schulte wrote: > > Moin, > > thanks for your reply > >> 1) allowing the user to specify a separator with a header argument as >> follows >> #+begin_src sh :var table=sec :separator , >> cat <> $table >> EOF >> #+end_src >> >> which would result in something like >> >> : "Hello, World" > > I like this idea because it is what I would expect. In my first > "experiment", I assumed that I can use the "|" as a separator. I would > like to use a table as input form and pipe the rows to a shell script > written in org-babel. Sometimes it is easier to proccess data with > awk instead of using elisp. So my example is a bit misleading. > >> 2) writing the table to a tab or comma separated file and then >> replacing =$table= in the source block body with the path to the >> file name, s.t. something like > > IMHO it is not necessary under Unix. Reading from stdin is usual. But it > maybe different under Windows. > > Many thanks > Matthias > > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode