Sujet : Re: "sed" question
De : 433-929-6894 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.awkDate : 09. Mar 2024, 21:49:43
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240309124320.907@kylheku.com>
References : 1 2 3 4 5 6
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-03-09, Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
On 09.03.2024 17:52, Ed Morton wrote:
About 20 or so years ago we had a discussion in this NG (which I'm not
going to search for now) and, shockingly, a consensus was reached that
we should encourage people to always write:
'{$2="1-1"} 1'
>
I don't recall such a "consensus". If you want to avoid cryptic code
you'd rather write
>
'{$2="1-1"; print}'
>
Don't you think?
I don't remember it either, but it's a no brainer that '$2=expr'
is incorrect if expr is arbitrary, and the intent is that
the implicit print is to be unconditionally invoked.
If expr is a nonblank, nonzero literal term, then the assignment
is obviously true and '$2=literal' as the entire program is a fine
idiom.
I don't agree with putting braces around it and adding 1, or explicit
print.
You are not then using Awk like it was meant to be.
When Awk was conceived, the authors peered into a crystal ball and saw
Perl. After the laughter died down, they got serious and made sure to
provide for idioms like:
awk '!s[$0]++'
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca