Hongyi Zhao wrote in <news:comp.unix.shell>:
> On Sat, 01 Oct 2016 20:23:08 +0200, Thomas 'PointedEars' Lahn wrote:
>
> Thanks a lot for your help.
You’re welcome.
> Now, another problem confusing me:
>
>> $ echo | gawk '{
>
> Above code can also be done with:
>
> $ gawk 'BEGIN{
Yes, thanks. I was trying to get rid of the pipe with here-doc but to no
avail; so I left the example this way.
> But, why your original method with `echo' also work?
Without arguments, (g)awk is reading from the standard input stream. Not
specifying a pattern for an action is equivalent to execute that action for
every line of input. (Not specifying an action for a pattern is equivalent
to '{ print }'.) See the section “PATTERNS AND ACTIONS” in the gawk man
page.
“echo” without arguments and redirection writes one empty line to the
standard output stream (it writes one newline character), so this code is
executed exactly one time as if the “BEGIN” pattern would have been used.
You should post (g)awk questions in <news:comp.lang.awk> instead. X-Post &
F'up2 set.