Date: Mon, 17 Apr 2017 10:11:32 -0400 From: Ernie Luzar <luzar722@gmail.com> To: Jim Trigg <jtrigg@huiekin.org> Cc: freebsd-questions@freebsd.org Subject: Re: awk help Message-ID: <58F4CD14.7090008@gmail.com> In-Reply-To: <7951DF71-5CD3-4B53-9CB4-13CAA8945983@huiekin.org> References: <58F25A01.1060208@gmail.com> <7951DF71-5CD3-4B53-9CB4-13CAA8945983@huiekin.org>
next in thread | previous in thread | raw e-mail | index | archive | help
>> On April 15, 2017 1:36:01 PM EDT, Ernie Luzar <luzar722@gmail.com> wrote: >> Hello list; >> >> Can not figure how to process 2 lines as a single line. >> I have this file. >> >> 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 0 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 0 Bytes 0 Name Ref 2 >> >> The Address line and the Hits line makes a pair. >> >> For any pair that hits is greater than zero >> output file with ip address with ; sufix instead of /32 and >> hit value in fixed position. >> >> I can't figure out how to code awk to process the 2 lines as a pair. >> >> All ready searched the online awk references and could not find an >> example. Any pointers would sure help. >> >> Thanks > > Jim Trigg wrote: > /^Address/ { address = $2; got_address = 1; } > /^ Hits/ { if (got_address) { > hits = $2; > if (hits) { > [Do what's needed with address and hits] > got_address = 0; > } else { > [Handle error condition of hits without address] > } > } > > Jim > Thank you Jim. Used this model as my starting point and accomplished my goal. When I first tested /^Address/ and /^ Hits/ produced no output. I changed them to /Address/ and /Hits/ and this produced output. I could not find any reference to the ^ sign, so I would like to know what is it suppose to do? I am not having success using the system commands rm & touch as shown in the following example. awk 'BEGIN { "date +%Y%m%d" | getline date hits_yes = "/etc/ipf_pool_awk_hits_yes" hits_no = "/etc/ipf_pool_awk_hits_no" rm hits_yes rm hits_no "touch hits_yes" "touch hits_no" }' $hits_rpt I know the date system command is working, but can't figure out how to code rm & touch to get them to work. Is this even possible? Thanks for any pointers.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?58F4CD14.7090008>