[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] -i infile unexpected behavior
From: |
arnold |
Subject: |
Re: [bug-gawk] -i infile unexpected behavior |
Date: |
Mon, 16 Mar 2015 01:30:43 -0600 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Andy,
I'm OK with this change if you wish to take the trouble to make it.
I don't mind the extra variable.
If you decide to do this, please send me a patch + ChangeLog entry to
review and I'll commit and merge.
Thanks.
Arnold
"Andrew J. Schorr" <address@hidden> wrote:
> On Sun, Mar 15, 2015 at 09:13:09PM -0500, Ed Morton wrote:
> > Andy - the script below behaved as desired in my testing. I'd never really
> > write or advocate anyone else writing the script below or
> >
> > gawk -e '1; ENDFILE {print "bar"}' -i inplace file
> >
> > though as the whole point of having
> >
> > awk -i inplace '...' file
> >
> > is to provide a briefer, simpler solution to write than
> >
> > awk '...' file > tmp && mv tmp file
> >
> > (analogous to "sed -i '...' file") and both of those are lengthier and more
> > complicated (even for multiple files) so then what would be the point?
>
> Well, the revision I provided does help a bit:
>
> bash-4.2$ echo foo > file
> bash-4.2$ cat /tmp/Inplace.awk
> # inplace --- load and invoke the inplace extension.
>
> @load "inplace"
>
> BEGINFILE {
> if (INPLACE_FILENAME)
> inplace_end(INPLACE_FILENAME, INPLACE_SUFFIX)
> inplace_begin(FILENAME, INPLACE_SUFFIX)
> INPLACE_FILENAME = FILENAME
> }
>
> END {
> inplace_end(FILENAME, INPLACE_SUFFIX)
> }
>
> bash-4.2$ awk -i /tmp/Inplace '1; ENDFILE {print "bar"}' file
> bash-4.2$ cat file
> foo
> bar
> bash-4.2$ awk -i /tmp/Inplace '1; END {print "bar"}' file
> bar
> bash-4.2$ cat file
> foo
> bar
> bash-4.2$
>
> It solves the "ENDFILE" problem, but does not fix the "END" case. The
> disadvantage is that we have to introduce a new global variable to
> store the filename.
>
> Is it worth making this change?
>
> Regards,
> Andy
- [bug-gawk] -i infile unexpected behavior, Ed Morton, 2015/03/15
- Re: [bug-gawk] -i infile unexpected behavior, Andrew J. Schorr, 2015/03/15
- Re: [bug-gawk] -i infile unexpected behavior, Ed Morton, 2015/03/15
- Re: [bug-gawk] -i infile unexpected behavior, Andrew J. Schorr, 2015/03/15
- Re: [bug-gawk] -i infile unexpected behavior, Ed Morton, 2015/03/15
- Re: [bug-gawk] -i infile unexpected behavior, Andrew J. Schorr, 2015/03/15
- Re: [bug-gawk] -i infile unexpected behavior, Ed Morton, 2015/03/15
- Re: [bug-gawk] -i infile unexpected behavior,
arnold <=
- Re: [bug-gawk] -i infile unexpected behavior, Andrew J. Schorr, 2015/03/17
- Re: [bug-gawk] -i infile unexpected behavior, Andrew J. Schorr, 2015/03/17
- Re: [bug-gawk] -i infile unexpected behavior, Andrew J. Schorr, 2015/03/15