Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Apr 2017 18:08:58 +0200
From:      Andreas Perstinger <andipersti@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: awk help
Message-ID:  <c95e03d2-986d-3c3c-198a-a28ab862dc70@gmail.com>
In-Reply-To: <58F4CD14.7090008@gmail.com>
References:  <58F25A01.1060208@gmail.com> <7951DF71-5CD3-4B53-9CB4-13CAA8945983@huiekin.org> <58F4CD14.7090008@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2017-04-17 16:11, Ernie Luzar wrote:
> 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?

"^" inside a regular expression is an anchor and matches the beginning
of the line. (See "man re_format" or e.g.
http://www.regular-expressions.info/anchors.html ). In the example
you've posted, the lines containing "Address" and "Hits" are indented
which means there are spaces/tabs between the beginning of the line and
these words. Thus the patterns don't match.

> 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

You need to use the built-in function "system" in order to use system
commands, e.g.

system("rm " hits_yes)

This concatenates the literal string "rm " with the content of the awk
variable "hits_yes" which results in the string "rm
/etc/ipf_pool_awk_hits_yes" and this command is then executed.

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

The "date" command works without using the "system" function because it
is part of the special syntax for the "getline" function.

But I wonder whether you really need to use commands like "rm" and
"touch" inside an awk script. What are you trying to accomplish?

Bye, Andreas



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c95e03d2-986d-3c3c-198a-a28ab862dc70>