From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roland Everaert Subject: Re: org babel table header sent to awk code block Date: Fri, 17 Feb 2017 16:00:52 +0100 Message-ID: References: <48db0e51591f4ff180507a99ea72ad5a@HE1PR01MB1898.eurprd01.prod.exchangelabs.com> <87shndc6cb.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114443a61bb9330548bb2e8b Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cek1n-0007Kt-H9 for emacs-orgmode@gnu.org; Fri, 17 Feb 2017 10:00:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cek1m-00017u-OL for emacs-orgmode@gnu.org; Fri, 17 Feb 2017 10:00:55 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34802) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cek1m-00017C-Gm for emacs-orgmode@gnu.org; Fri, 17 Feb 2017 10:00:54 -0500 Received: by mail-wm0-x241.google.com with SMTP id c85so3008925wmi.1 for ; Fri, 17 Feb 2017 07:00:54 -0800 (PST) In-Reply-To: <87shndc6cb.fsf@ucl.ac.uk> 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" To: Eric S Fraga , emacs-orgmode --001a114443a61bb9330548bb2e8b Content-Type: text/plain; charset=UTF-8 I see that more or less 30 seconds after posting to the ML :/ So the problem of this script is solved. But anyway, why are column headers sent to the script, even with :hlines and/or :colnames set approriately? Thanks. On Fri, Feb 17, 2017 at 2:08 PM, Eric S Fraga wrote: > On Friday, 17 Feb 2017 at 12:33, Roland Everaert wrote: > > Hi, > > > > I am trying to filter a table using the following awk code block. > > I think your problem is an error in the awk script; specifically, the > match is outputting all lines because you need to have the { on the same > line as the match expression. Try this: > > #+BEGIN_SRC awk :stdin list-example :var fstcol=1 :var seccol=3 :results > output org > BEGIN { > print "|Host|Result" > print "|-" > } > $seccol ~ /[0-9]{1,3}(\.[0-9]\{1,3\}){3}/ { > print "|"$fstcol"|"$seccol > } > #+END_SRC > > You may have noticed that the second line (which had an empty third > column so should not have matched) was also being output when it > shouldn't have. > > In any case, the above works for me. > > HTH, > eric > > -- > : Eric S Fraga (0xFFFCF67D), Emacs 26.0.50.1, Org release_9.0.4-242-g2c27b8 > --001a114443a61bb9330548bb2e8b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I see that more or less 30 seconds after posting= to the ML :/

So the problem of this script is solved.

But anyway, why are column headers sent to the script= , even with :hlines and/or :colnames set approriately?

Thanks.=

On Fri,= Feb 17, 2017 at 2:08 PM, Eric S Fraga <e.fraga@ucl.ac.uk> w= rote:
On Friday, 17 Feb = 2017 at 12:33, Roland Everaert wrote:
> Hi,
>
> I am trying to filter a table using the following awk code block.

I think your problem is an error in the awk script; specifically, th= e
match is outputting all lines because you need to have the { on the same line as the match expression.=C2=A0 Try this:

#+BEGIN_SRC awk :stdin list-example :var fstcol=3D1 :var seccol=3D3 :result= s output org
=C2=A0 BEGIN {
=C2=A0 print "|Host|Result"
=C2=A0 print "|-"
=C2=A0 }
=C2=A0 $seccol ~ /[0-9]{1,3}(\.[0-9]\{1,3\}){3}/ {
=C2=A0 print "|"$fstcol"|"$seccol
=C2=A0 }
#+END_SRC

You may have noticed that the second line (which had an empty third<= br> column so should not have matched) was also being output when it
shouldn't have.

In any case, the above works for me.

HTH,
eric

--
: Eric S Fraga (0xFFFCF67D), Emacs 26.0.50.1, Org release_9.0.4-242-g2c27b8=

--001a114443a61bb9330548bb2e8b--