This is good for saving disk IO, but I'm always wary of reading and writing
to a file in the same step. I just can't trust that the read will _always_
finish before the write begins. So the risk is greater than the reward, for
me, in this case.

-wes

On Mon, Jul 27, 2015 at 11:19 AM, David Gibbons <[email protected]> wrote:

> Rather than creating a temp file, you can also subshell out and cat the
> current contents, this executes before the command that wraps it so you
> don't worry about clobbering the contents before reading them.
>
> for filename in /path/to/app/source/*py
>
> do if ! grep wxversion $filename
>
> then echo "import wxversion
> wxversion.select('3.0.2.0')
> import os, time, wx
>
> $(cat $filename)" > $filename
>
> fi
>
> done
>
> On Mon, Jul 27, 2015 at 10:54 AM, wes <[email protected]> wrote:
>
> > On Mon, Jul 27, 2015 at 7:55 AM, Rich Shepard <[email protected]>
> > wrote:
> >
> > >
> > >    Before writing such a script advice on a (or most) appropriate tool
> > > would
> > > be helpful. Would awk be the appropriate tool for this? Should be a
> short
> > > script so perhaps a linux utility would be a parsimonious working
> > solution.
> > >
> > > Rich
> > >
> > >
> > Awk is for modifying existing data. You are adding completely new lines,
> so
> > the best tool for the job would be cat.
> >
> > for filename in /path/to/app/source/*py
> >
> > do if ! grep wxversion $filename
> >
> > then echo "import wxversion
> > wxversion.select('3.0.2.0')
> > import os, time, wx" > $filename.new
> >
> > cat $filename >> $filename.new
> >
> > mv $filename.new $filename
> >
> > fi
> >
> > done
> >
> > -wes
> > _______________________________________________
> > PLUG mailing list
> > [email protected]
> > http://lists.pdxlinux.org/mailman/listinfo/plug
> >
> _______________________________________________
> PLUG mailing list
> [email protected]
> http://lists.pdxlinux.org/mailman/listinfo/plug
>
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to