[PLUG] The Right Tool For the Job

wes plug at the-wes.com
Mon Jul 27 18:26:59 UTC 2015


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 <david at dgibbons.net> 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 <plug at the-wes.com> wrote:
>
> > On Mon, Jul 27, 2015 at 7:55 AM, Rich Shepard <rshepard at appl-ecosys.com>
> > 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
> > PLUG at lists.pdxlinux.org
> > http://lists.pdxlinux.org/mailman/listinfo/plug
> >
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>



More information about the PLUG mailing list