bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] in-place edit request


From: Davide Brini
Subject: Re: [bug-gawk] in-place edit request
Date: Wed, 2 Jan 2013 21:59:16 +0100

On Wed, 02 Jan 2013 21:33:57 +0200, Aharon Robbins <address@hidden>
wrote:

> Hi Manuel.
> 
> > Just an additional thought. The -i behavior of Perl and Ruby, is
> > usually combined with an additional -p flag that makes the final
> > 'print' statement unnecessary.
> 
> In sed the -p counters a #n or -n option. I don't know (nor particularly
> care) what Ruby does.

Sed autoprints lines by default, and uses -n to disable this behavior;
there's no -p *option* (you are probably thinking about the the sed "p"
*command* to explicitly print the pattern space).

Yes, i know awk is not perl, but just for clarity:

What perl does is it has a -n option to introduce an automatic loop over
the input (the thing that sed and awk do automatically), which however
requires explicitly printing the line if wanted (ie, like sed -n or plain
awk); but then perl also supports a -p option, which does the same as -n
but also autoprints the lines (like sed). AFACT, ruby supports both -n and
-p with the same semantics as perl.

So basically in this respect awk behaves like "perl -n" and like "sed -n",
where if you want to print you have to do it explicitly.
 
> > I.e., in gawk it would implicitly add a final '{print}' rule 
> > to the whole awk program. This -p flags makes sense by itself, not only
> > as a -i companion.
> 
> I don't think so.

So *if* gawk were to have a -p option (or equivalent), it would be like
having that "{print}", or "1" or whatever at the end, only without having to
write it; in other words, it would behave like "sed" without -n, or like
"perl -p".

For the record, I'm not advocating in-place editing neither having -p; it's
just to clarify things.

Regards,

-- 
D.



reply via email to

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