emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Re: [babel] How to kill two birds with one stone?


From: Sébastien Vauban
Subject: [Orgmode] Re: [babel] How to kill two birds with one stone?
Date: Fri, 25 Feb 2011 15:27:29 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (windows-nt)

Hi Eric,

First, thanks for answering this open thread!

"Eric Schulte" wrote:
> I haven't followed this discussion very closely, but I'm not sure why it
> would be necessary to pass data through STDIN rather than through a variable
> or an external file.

I'll comment on the full problem (or solution) later on. But I'd like to share
a first problem with you.

> I took a shot at the dot graph example you proposed, the following works for
> me over a simple example directory.

I've redone (almost) the same file structure as yours, so that our results
must be similar, if not equal.

> directory to search
> #+results: graph-dir
> : graph-dir
>
> list all files in dir
> #+source: graph-files
> #+begin_src sh :results vector :var dir=graph-dir
>   find $dir -type f -exec basename {} \;
> #+end_src
>
> #+results: graph-files
> | other |
> | dan   |
> | eric  |
> | seb   |
>
> association of files with mentions
> #+source: graph-associations
> #+begin_src sh :var dir=graph-dir :var files=graph-files
>   for i in $files; do
>       for j in `grep -l -r $i $dir`;do
>           echo $i, `basename $j`
>       done
>   done
> #+end_src
>
> #+results: graph-associations
> | other | eric |
> | other | seb  |
> | dan   | eric |
> | eric  | seb  |
> | seb   | dan  |

My adapted version of your first paragraphs:

* Directory to search

#+results: graph-dir
: graph-dir

* List all files in dir (version of Eric)

#+source: graph-files
#+begin_src sh :results vector :var dir=graph-dir
  find $dir -type f -exec basename {} \;
#+end_src

#+results: graph-files
| dan   |        |
| eric  |        |
| other |        |
| seb   | vauban |

* List all files in dir (version of Seb)

My code was a bit more complex... because I need to be able to correctly take
care of filenames containing spaces inside them (I'm on Windows, I never do
such a thing, but there are well spaces on the files I wanna graph).

#+srcname: graph-files-seb
#+begin_src sh :results vector :var dir=graph-dir
  find $dir -type f -print |\
  while read -r name
  do
      echo "\"${name##*/}\""
  done
#+end_src

#+results: graph-files-seb
| dan   |         |
| eric  |         |
| other |         |
| "seb  | vauban" |

Spaces are used as colon delimiters: they win over my double quotes.

* List all files in dir (version of Seb)

Just to show, this code prints a semi-colon after every filename.

#+srcname: graph-files-seb2
#+begin_src sh :results vector :var dir=graph-dir
  find $dir -type f -print |\
  while read -r name
  do
      echo "\"${name##*/}\";"
  done
#+end_src

#+results: graph-files-seb2
| dan   |          |
| eric  |          |
| other |          |
| "seb  | vauban"; |

In most cases, these have been eaten as well...

Is it possible to circumvent this problem, and get my filenames (even those
with spaces in them) in one column?

Best regards,
  Seb

-- 
Sébastien Vauban




reply via email to

[Prev in Thread] Current Thread [Next in Thread]