Eric S Fraga <e.fr...@ucl.ac.uk> writes:

> Eric Schulte <schulte.e...@gmail.com> writes:
>
> [...]
>
>> As an example, I've worked up an very simple ob-awk.el file from
>> ob-template.el, it is attached along with an example org-mode file which
>> demonstrates its usage.
>
> Eric,
>
> this is great to see as I use awk quite often.  What is involved in
> extending this to be able to run an awk script on input from within the
> org file (output of another babel block, for instance, as my typical use
> of awk is to re-arrange output from another program...)?  Or, if you
> wish, can you suggest one of the ob-XXX modules that best illustrates
> how to do this and I can give it a try?
>

I've made a quick change so that any variable named "stdin" is treated
specially, in that, rather than using its value to replace strings of
$stdin in the text of the awk code, the value of the stdin variable is
saved into the file processed by awk.  This allows awk to operate over
Org-mode references.

See the attached example file.

If babel code block supported a pipe or an actual stdin header argument,
that would be the ideal way to add this behavior, but currently nothing
of that nature exists.

Please let me know if this misses part of your suggestion, or more
generally what else may be advisable before we add this to the core.

Cheers -- Eric

* awk example

#+results: simple-table
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |

#+begin_src awk :var stdin=simple-table
  {print $1}
#+end_src

#+results:
: 1
: 4
: 7

#+results: simple-text
: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
: eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad
: minim veniam, quis nostrud exercitation ullamco laboris nisi ut
: aliquip ex ea commodo consequat. Duis aute irure dolor in
: reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
: pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
: culpa qui officia deserunt mollit anim id est laborum.

Attachment: ob-awk.el
Description: application/emacs-lisp

>
> Thanks,
> eric

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

Reply via email to