emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using Code Blocks in Org Tables
@ 2011-08-26  3:49 Henri-Paul Indiogine
  2011-08-26 14:58 ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Henri-Paul Indiogine @ 2011-08-26  3:49 UTC (permalink / raw)
  To: emacs-org

I am trying to have the final output of several bash script appear in
a summary table.

I am trying to follow this example:
http://orgmode.org/worg/org-contrib/babel/intro.html#spreadsheet

This is my test system:

-------------------------8<--------------------------->8---------------------
#+tblname: test
#+CAPTION: test
#+LABEL: tbl:test
| collection     | number               |
|----------------+----------------------|
| congr-hearings | (("/home/henk") (2)) |
| congr-bills    |                      |
| pres-docs      |                      |
| eric-docs      |                      |
#+TBLFM: @2$2='(sbe "test-sh")

#+srcname: test-sh
#+begin_src sh  :results value
x=2
echo $HOME
echo $x
#+end_src

#+results: test-sh
| /home/henk |
|          2 |

---------------------------8<--------------------->8----------------

I want actually to have only the number "2" in cell @2$2.  I thought
that with ":results value" only the final output of the script, i.e.
the output of "echo $x" would appear.  Instead the results of all echo
statement do appear.

What am I doing wrongly?

Thanks,
Henri-Paul




-- 
Henri-Paul Indiogine

Curriculum & Instruction
Texas A&M University
TutorFind Learning Centre

Email: hindiogine@gmail.com
Skype: hindiogine
Website: http://people.cehd.tamu.edu/~sindiogine

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Using Code Blocks in Org Tables
  2011-08-26  3:49 Using Code Blocks in Org Tables Henri-Paul Indiogine
@ 2011-08-26 14:58 ` Eric Schulte
  2011-08-26 21:35   ` Henri-Paul Indiogine
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2011-08-26 14:58 UTC (permalink / raw)
  To: Henri-Paul Indiogine; +Cc: emacs-org

Henri-Paul Indiogine <hindiogine@gmail.com> writes:

> I am trying to have the final output of several bash script appear in
> a summary table.
>
> I am trying to follow this example:
> http://orgmode.org/worg/org-contrib/babel/intro.html#spreadsheet
>
> This is my test system:
>
> -------------------------8<--------------------------->8---------------------
> #+tblname: test
> #+CAPTION: test
> #+LABEL: tbl:test
> | collection     | number               |
> |----------------+----------------------|
> | congr-hearings | (("/home/henk") (2)) |
> | congr-bills    |                      |
> | pres-docs      |                      |
> | eric-docs      |                      |
> #+TBLFM: @2$2='(sbe "test-sh")
>
> #+srcname: test-sh
> #+begin_src sh  :results value
> x=2
> echo $HOME
> echo $x
> #+end_src
>
> #+results: test-sh
> | /home/henk |
> |          2 |
>
> ---------------------------8<--------------------->8----------------
>
> I want actually to have only the number "2" in cell @2$2.  I thought
> that with ":results value" only the final output of the script, i.e.
> the output of "echo $x" would appear.  Instead the results of all echo
> statement do appear.
>

sh code blocks are different in that they don't really have a ":results
value" option in the same way as most code blocks.  Two options would be
to either
1. remove the "echo $HOME" line from your code blocks, or
2. change the '(sbe "test-sh") formula to '(second (second (sbe "test-sh")))

>
> What am I doing wrongly?
>

Nothing wrong, you just weren't aware of the idiosyncrasies of the sh
code blocks.  I suppose that we could change the behavior of ":results
value" on sh blocks such that it only returns the last line of output,
but depending on who you ask "value" means different things on sh blocks
(e.g., possibly the return value of the last statement $?).

Best -- Eric

>
> Thanks,
> Henri-Paul

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Using Code Blocks in Org Tables
  2011-08-26 14:58 ` Eric Schulte
@ 2011-08-26 21:35   ` Henri-Paul Indiogine
  2011-08-28 14:55     ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Henri-Paul Indiogine @ 2011-08-26 21:35 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-org

Hi Eric!

2011/8/26 Eric Schulte <schulte.eric@gmail.com>:
> sh code blocks are different in that they don't really have a ":results
> value" option in the same way as most code blocks.  Two options would be
> to either
> 1. remove the "echo $HOME" line from your code blocks, or
> 2. change the '(sbe "test-sh") formula to '(second (second (sbe "test-sh")))

I was going by: http://orgmode.org/worg/org-contrib/babel/intro.html#results

Capturing the results of code evaluation.
The 'result' of code evaluation is the value of the last statement in
the code block. ....

I have a long bash script that outputs a lot of information to a log
file.   But I would like one piece of information to end up in a cell
of an org-mode table.   I can place this value as the last one in the
bash script.  How could I make that work?

Thanks,
Henri-Paul

-- 
Henri-Paul Indiogine

Curriculum & Instruction
Texas A&M University
TutorFind Learning Centre

Email: hindiogine@gmail.com
Skype: hindiogine
Website: http://people.cehd.tamu.edu/~sindiogine

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Using Code Blocks in Org Tables
  2011-08-26 21:35   ` Henri-Paul Indiogine
@ 2011-08-28 14:55     ` Eric Schulte
  2011-08-29  5:38       ` Henri-Paul Indiogine
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2011-08-28 14:55 UTC (permalink / raw)
  To: Henri-Paul Indiogine; +Cc: emacs-org

Henri-Paul Indiogine <hindiogine@gmail.com> writes:

> Hi Eric!
>
> 2011/8/26 Eric Schulte <schulte.eric@gmail.com>:
>> sh code blocks are different in that they don't really have a ":results
>> value" option in the same way as most code blocks.  Two options would be
>> to either
>> 1. remove the "echo $HOME" line from your code blocks, or
>> 2. change the '(sbe "test-sh") formula to '(second (second (sbe "test-sh")))
>
> I was going by: http://orgmode.org/worg/org-contrib/babel/intro.html#results
>
> Capturing the results of code evaluation.
> The 'result' of code evaluation is the value of the last statement in
> the code block. ....
>
> I have a long bash script that outputs a lot of information to a log
> file.   But I would like one piece of information to end up in a cell
> of an org-mode table.   I can place this value as the last one in the
> bash script.  How could I make that work?
>

Hi Henri-Paul,

You could define another code block which could be used to take just the
last line of the output, e.g.,

#+source: stuff
#+begin_src sh
  echo 1
  echo 2
  echo 3
#+end_src

#+source: last-of-stuff
#+begin_src sh :var input=stuff
  echo "$input" |tail -1
#+end_src

| one |
| two |
| 3   |
#+TBLFM: @3$1='(sbe last-of-stuff)

Hope this helps -- Eric

>
> Thanks,
> Henri-Paul

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Using Code Blocks in Org Tables
  2011-08-28 14:55     ` Eric Schulte
@ 2011-08-29  5:38       ` Henri-Paul Indiogine
  0 siblings, 0 replies; 5+ messages in thread
From: Henri-Paul Indiogine @ 2011-08-29  5:38 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-org

Hi Eric!

2011/8/28 Eric Schulte <schulte.eric@gmail.com>:
>
> #+source: last-of-stuff
> #+begin_src sh :var input=stuff
>  echo "$input" |tail -1
> #+end_src
>
> | one |
> | two |
> | 3   |
> #+TBLFM: @3$1='(sbe last-of-stuff)

Your solution works very well.

Thanks!

Henri-Paul


-- 
Henri-Paul Indiogine

Curriculum & Instruction
Texas A&M University
TutorFind Learning Centre

Email: hindiogine@gmail.com
Skype: hindiogine
Website: http://people.cehd.tamu.edu/~sindiogine

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-08-29  5:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-26  3:49 Using Code Blocks in Org Tables Henri-Paul Indiogine
2011-08-26 14:58 ` Eric Schulte
2011-08-26 21:35   ` Henri-Paul Indiogine
2011-08-28 14:55     ` Eric Schulte
2011-08-29  5:38       ` Henri-Paul Indiogine

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).