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

Reply via email to