From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Table filter. Date: Tue, 08 May 2012 11:10:37 -0400 Message-ID: <12562.1336489837@alphaville> References: <87vck7dn04.fsf@cica.cica> <87mx5jvw0p.fsf@gnu.org> <87havrdk4m.fsf@cica.cica> <87zk9izw6d.fsf@gnu.org> Reply-To: nicholas.dokos@hp.com Return-path: Received: from eggs.gnu.org ([208.118.235.92]:58400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRm3r-0004Ny-Vq for emacs-orgmode@gnu.org; Tue, 08 May 2012 11:10:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRm3p-0000YW-Rb for emacs-orgmode@gnu.org; Tue, 08 May 2012 11:10:47 -0400 In-Reply-To: Message from Bastien of "Tue, 08 May 2012 14:36:42 +0200." <87zk9izw6d.fsf@gnu.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: emacs-orgmode@gnu.org, Petro Bastien wrote: > Hi Petro, > > Petro writes: > > > lets say I have a table > > > > | n | 2 | 3 | 4 | 5 | 6 | > > |---+---+---+---+---+---| > > | 1 | a | | | | | > > | 2 | b | | | | | > > | 3 | b | | | | | > > | 4 | a | | | | | > > | 5 | c | | | | | > > | 6 | b | | | | | > > | 7 | a | | | | | > > > > I want to filter this table and get only rows where second column equal a > > | n | 2 | 3 | 4 | 5 | 6 | > > |---+---+---+---+---+---| > > | 1 | a | | | | | > > | 4 | a | | | | | > > | 7 | a | | | | | > > Such feature does not exist for now, but I would welcome enhancements in > this direction. Thanks for this idea, > You can get most of the way there with babel, as long as you don't insist on modifying the table in place. Something like this e.g. using python 2.x: --8<---------------cut here---------------start------------->8--- #+BEGIN_SRC elisp (setq org-babel-min-lines-for-block-output 0) #+END_SRC #+RESULTS: #+begin_example 0 #+end_example The above setting is just to force an example block. The default value (10) produces colon-demarcated results. #+name: orig | n | 2 | 3 | 4 | 5 | 6 | |---+---+---+---+---+---| | 1 | a | | | | | | 2 | b | | | | | | 3 | b | | | | | | 4 | a | | | | | | 5 | c | | | | | | 6 | b | | | | | | 7 | a | | | | | #+BEGIN_SRC python :var table=orig :results output # print the header print "#+name: filtered" for x in table: if x[1] == 'a': print "|%s" % ("|".join(map(str, x))) #+END_SRC #+RESULTS: #+begin_example #+name: filtered |1|a|||| |4|a|||| |7|a|||| #+end_example --8<---------------cut here---------------end--------------->8--- I don't know how to get the column heading row though: apparently babel strips it from the table it passes to the code block. Nick