bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a way to add a rule without blocking?


From: Wolfgang Laun
Subject: Re: Is there a way to add a rule without blocking?
Date: Tue, 17 Mar 2020 20:54:05 +0100

On Tue, 17 Mar 2020 at 19:55, Peng Yu <address@hidden> wrote:

> I want to just use mygawk to have a uniform entry to call instead of
> sometimes use mygawk and some times use gawk. So the problem is what
> if the input is not specified instead of the other way around.
>

You haven't provided a meaningful use case, i.e., some additional awk rules
to be applied to some input. Your mygawk all by itself doesn't make sense
with any input, 0 or more lines.

OTOH, why don't you do this:
   alias mygawk='gawk -e "NF==0 { NF=1 }" </dev/null'

-W






>
> On 3/17/20, Wolfgang Laun <address@hidden> wrote:
> > How would your mygawk ever be useful without additional rules? And as
> soon
> > you have additional rules, gawk will want to read some input file, which
> > you'll have to provide on the shell command.
> >
> > -W
> >
> > On Tue, 17 Mar 2020 at 18:49, Peng Yu <address@hidden> wrote:
> >
> >> I want to create a shell alias of gawk with the following command
> >> initial.
> >>
> >> alias mygawk='gawk -e '\''!NF { NF=1 }'\'
> >>
> >> So that I can change the default of an empty line for NF to 1.
> >>
> >> $ mygawk -e '{ print NF }' <<< ''
> >> 1
> >> $ gawk -e '{ print NF }' <<< ''
> >> 0
> >>
> >> But it will block when no input is provided. Is there a way to get rid
> >> of the hang problem, yet still modify gawk so that NF will be set to 1
> >> by default for empty input lines.
> >>
> >> $ mygawk -e 'BEGIN { print "Hello World!" }' # This will hang.
> >> Hello World!
> >>
> >> $ gawk -e 'BEGIN { print "Hello World!" }' # This does not hang.
> >> Hello World!
> >>
> >> --
> >> Regards,
> >> Peng
> >>
> >>
> >
>
>
> --
> Regards,
> Peng
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]