emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sebastien Vauban" <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org>
To: emacs-orgmode-mXXj517/zsQ@public.gmane.org
Subject: Re: org babel support for tcl and awk
Date: Thu, 26 May 2011 13:18:43 +0200	[thread overview]
Message-ID: <8039k1r9po.fsf@somewhere.org> (raw)
In-Reply-To: 87oc2qhixx.fsf@gmail.com

Hi Eric,

Eric Schulte wrote:
>> As you can see, I did not really mean any concurrent execution. Simply
>> being able to execute parts of code in-situ, in the Org buffer, to document
>> (and test) what I'm writing.
>>
>> And to be able to assemble all the parts in one single script file, by the
>> means of literate programming.
>
> I see, you want to be able to construct a large pipe chain STDOUT>STDIN,

That's it!

> but you don't care if the parts of the chain (e.g., the code block) execute
> in serial or concurrently (as they do in the shell).

For me, there is no concept of serial or concurrent execution here, as I am
executing manually the calls, when writing the Org document.

Not sure to understand you...

Are you talking of what happens for the export, maybe?

Are you talking of the shell constructs which will be used in the way the
"full script" is assembled?

> The attached patch (can be applied with "git am") implements this
> behavior as I understand it.  The result is a new :stdin header argument
> with which org-mode references can be passed to shell scripts as
> standard input.  Given the technique used in this patch, I'll probably
> re-write part of ob-awk.el.

Your patch is simply wonderful. It completely meets my need!  Thanks a lot.

Look with the updated (and, now working) example of yesterday.

* Abstract

This script "americanizes" a European CSV file.

* Sample data

The following is a sample CSV file:

#+results: sample-csv
#+begin_example
Date;Amount;Account
28-05-2010;-6.806,25;999-1974050-30
04-06-2009;420,00;999-1500974-23
24-02-2009;-54,93;999-1974050-30
#+end_example

This input data will be used to show what the results of the transformations
are.

* Script

What the script must do is:

** Convert the date in American format

Convert the date in =MM/DD/YYYY= format.

#+srcname: convert-date
#+begin_src sh :stdin sample-csv :results output :exports both
sed -r 's/^([[:digit:]]{2})-([[:digit:]]{2})-([[:digit:]]{4})/\2\/\1\/\3/g'
#+end_src

#+results: convert-date
#+begin_example
Date;Amount;Account
05/28/2010;-6.806,25;999-1974050-30
06/04/2009;420,00;999-1500974-23
02/24/2009;-54,93;999-1974050-30
#+end_example

** Convert the separators

Apply the following operations in order to "americanize" the CSV file received
from the bank:

- remove the dot used as thousands separator (=.= -> ==)
- replace the comma used as decimal separator by a dot (=,= -> =.=)
- replace other commas by a dot (=,= -> =.=)
- replace the semi-comma used as field separator by a comma (=;= -> =,=)

#+srcname: convert-separators
#+begin_src sh :stdin convert-date :results output :exports both
sed -r 's/([[:digit:]])\.([[:digit:]]{3})/\1\2/g' |\
sed -r 's/([[:digit:]]),([[:digit:]]{2})/\1.\2/g' |\
sed -r 's/,/./g' |\
sed -r 's/;/,/g'
#+end_src

#+results: convert-separators
#+begin_example
Date,Amount,Account
05/28/2010,-6806.25,999-1974050-30
06/04/2009,420.00,999-1500974-23
02/24/2009,-54.93,999-1974050-30
#+end_example

* Full code

The script is then:

#+begin_src sh :tangle americanize-csv.sh :noweb yes
#!/bin/bash
# americanize-csv.sh -- Convert CSV file to American format

# Usage: americanize-csv FILE.CSV

cat $1 |\
<<convert-date>> |\
<<convert-separators>>

exit 0

# americanize-csv.sh ends here
#+end_src

* Conclusions

The new =stdin= option allows one to:

- execute parts of code in-situ, in the Org buffer, documenting (and testing)
  them.

- assemble all the parts in one single script file, by the means of literate
  programming.

Go for applying it!

Thanks a lot, Eric, for your time.

Best regards,
  Seb

-- 
Sébastien Vauban

  reply	other threads:[~2011-05-26 11:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-24  9:31 org babel support for tcl and awk orgmode
2011-05-24 12:51 ` Eric Schulte
2011-05-24 17:53   ` Eric S Fraga
2011-05-24 19:03     ` Eric Schulte
2011-05-24 19:55       ` Sebastien Vauban
2011-05-24 23:51         ` Eric Schulte
2011-05-25 12:30           ` Sebastien Vauban
2011-05-25 15:57             ` Eric Schulte
2011-05-26 11:18               ` Sebastien Vauban [this message]
2011-05-26 13:37                 ` Eric Schulte
2011-05-26 13:03       ` Eric Schulte
2011-05-26 15:15         ` Eric S Fraga
2011-05-24 18:57   ` orgmode

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=8039k1r9po.fsf@somewhere.org \
    --to=wxhgmqzgwmuf-genee64ty+gs+fvcfc7uqw@public.gmane.org \
    --cc=emacs-orgmode-mXXj517/zsQ@public.gmane.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).