[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Count empty line as a column with one empty field
From: |
arnold |
Subject: |
Re: [bug-gawk] Count empty line as a column with one empty field |
Date: |
Wed, 26 Sep 2018 03:39:03 -0600 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Peng Yu <address@hidden> wrote:
> Hi,
>
> I see this.
>
> $ printf '%s\n' a '' b | awk -e '{print NF}'
> 1
> 0
> 1
>
> Is it possible to consider the empty line to contain one empty field
> instead of no fields?
>
> [ ..... ]
>
> I am not saying it is a bug, either.
>
> A row with an empty field, instead of an empty row, is just another
> way to interpret in the input. Both are fine depending on the context.
> In certain cases, the former may be preferred over the latter.
There isn't any way to do this with the language. But as Davide Brini
suggests:
> $ printf '%s\n' a '' b | awk '!NF{$1=""} {print NF}'
> 1
> 1
> 1
Arnold