Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Apr 2017 21:50:56 +0200
From:      Andreas Perstinger <andipersti@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: awk help
Message-ID:  <20170415215056.6ab57316@Hof>
In-Reply-To: <58F25A01.1060208@gmail.com>
References:  <58F25A01.1060208@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Ernie Luzar <luzar722@gmail.com> wrote:
>I can't figure out how to code awk to process the 2 lines as a pair.

You could use awk's built-in "getline" function in order to process the
following line after you are done with the current one:

$ cat awk_help.txt
poollist: opts = 0x2
Name: test Role: ipf    References: 2   Hits: 0
        Nodes Starting at 0xc9fd4800
        Address: 1.11.244.65/32
                Hits 0  Bytes 0 Name    Ref 2
        Address: 1.163.113.139/32
                Hits 0  Bytes 0 Name    Ref 2
        Address: 1.163.139.214/32
                Hits 2  Bytes 0 Name    Ref 2
        Address: 1.173.51.202/32
                Hits 0  Bytes 0 Name    Ref 2
        Address: 1.175.164.129/32
                Hits 0  Bytes 0 Name    Ref 2
        Address: 99.197.14.34/32
                Hits 3  Bytes 0 Name    Ref 2
$ awk '/Address/ {address = substr($2, 1, length($2)-3); getline; if ($2) printf "%s;\t%s\n", address, $2}' awk_help.txt
1.163.139.214;  2
99.197.14.34;   3

Bye, Andreas



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170415215056.6ab57316>