emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org babel table header sent to awk code block
@ 2017-02-17 12:33 Roland Everaert
  0 siblings, 0 replies; 3+ messages in thread
From: Roland Everaert @ 2017-02-17 12:33 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 927 bytes --]

Hi,

I am trying to filter a table using the following awk code block.
#+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

The input table:

    #+NAME: list-example
    | A      |            B |            C |
    |--------+--------------+--------------|
    | blabla |  12.147.5.74 | 10.23.31.189 |
    | test   |  147.12.5.74 |              |
    | hello  | 79.147.64.74 | 10.23.31.189 |


And the result is:


#+RESULTS:
#+BEGIN_SRC org
| Host   |       Result |
|--------+--------------|
| A      |            C |
| blabla | 10.23.31.189 |
| test   |              |
| hello  | 10.23.31.189 |
#+END_SRC


Why the column names of the table are sent to awk?

I have tried to set :colnames and :hlines, but that doesn't change the
behavior.


Regards.

[-- Attachment #2: Type: text/html, Size: 1310 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: org babel table header sent to awk code block
       [not found] <48db0e51591f4ff180507a99ea72ad5a@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2017-02-17 13:08 ` Eric S Fraga
  2017-02-17 15:00   ` Roland Everaert
  0 siblings, 1 reply; 3+ messages in thread
From: Eric S Fraga @ 2017-02-17 13:08 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: org babel table header sent to awk code block
  2017-02-17 13:08 ` Eric S Fraga
@ 2017-02-17 15:00   ` Roland Everaert
  0 siblings, 0 replies; 3+ messages in thread
From: Roland Everaert @ 2017-02-17 15:00 UTC (permalink / raw)
  To: Eric S Fraga, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]

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> 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
>

[-- Attachment #2: Type: text/html, Size: 1792 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-17 15:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-17 12:33 org babel table header sent to awk code block Roland Everaert
     [not found] <48db0e51591f4ff180507a99ea72ad5a@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-02-17 13:08 ` Eric S Fraga
2017-02-17 15:00   ` Roland Everaert

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).