[Top][All Lists]

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

Re: OT: automation

From: olafBuddenhagen
Subject: Re: OT: automation
Date: Sun, 1 Nov 2009 11:54:28 +0100
User-agent: Mutt/1.5.19 (2009-01-05)

On Wed, Oct 28, 2009 at 05:23:13PM +0100, Arne Babenhauserheide wrote:
> Am Sonntag, 25. Oktober 2009 11:23:59 schrieb olafBuddenhagen@gmx.net:

> > That's a very bad thing to do. I hate all these mmv and other
> > bullshit
> mmv? 

"multi move" or something like that -- a program for renaming multiple
files at once. The type of stuff one normally uses for loops for...

Another variant is zmv, which is part of zsh. I comes with its whole own
language for specifying non-trivial filename patterns... Which is just
idiocy. People would be much better off spending the time on learning
generic for and sed instead, which comes in handy in other situations as
well, instead of a single-purpose language only for this.

> > *much* more valuable knowledge than usage of any specific scripts.
> > This generic knowledge, once obtained, can be reused in all kinds of
> > situations.
> What I use of my shell is for loops, some globbing, pipes with sed,
> grep, find, and such. 

Yeah, these are exactly the generic tools I mean.

> The reason I prefer python scripting is mainly shell escaping, which
> can really hurt :( 
> Sometimes I haggle for minutes with a sed script, before I get it
> right. I think I should write me a python script which just takes
> stdin and some python commands as input, executes the commands on the
> file and pipes the result to stdout... 
> Something like ... damn ... del 10 lines of unnecessary script ... 
> find -print0 | python -c "from sys import stdin;from os.path import
> isfile files = stdin.read() for f in files.split('\0'): if isfile(f):
> data = open(f).read() d = data.split('orig') print 'new'.join(d) "
> (replace "print..." with "open(f, 'w').write('new'.join(d))" to
> replace in files)
> This is more verbose than a "find (only files) | sed -i s/orig/new/",
> but it saves me from having to escape all kind of weird stuff in
> sed... 

So you want:

   find -type f -print0|xargs -0 -L 1 echo sed -i 's/orig/new/'

Where does escaping come in here at all?... (Unless you mean the actual
sed script, which is usually a constant string, and it's generally a
good idea to put it in single quotes -- I never even considered leaving
these out...)

Of course there are other situations where escaping is indeed necessary.
However, most of the time it boils down to learning to use "$i" instead
of bare $i:

   for i in *; do mv "$i" `<<<"$i" sed 's/\.JPG$/\.jpeg$/'`; done

I agree though that quoting is the single most problematic issue in
shell scripting.

> > This is what UNIX -- and for me at least, also the Hurd -- is really
> > all about.
> But it's only useful to people who often have to do these kinds of
> tasks. 
> Just look at the viewpoint of a writer instead. He needs to be able to
> write text and sometimes replace some words in a list of files. 

Except that the average writer won't use text files at all, but rather
something like OpenOffice; so you'd have to provide him with a StarBasic
macro or something...

Of course you can teach a writer to use text files, because text files
are more powerful -- but they are only more powerful if you also teach
him the stuff which can actually deal better with text files... Which is
shell scripting.

> Learning the intricacies of cat and sed won't help him - he will lose
> far more time than he wins, since he can just use a script which does
> what he needs to do - or get someone to write it for him. 
> It's far less versatile than the shell, but it does what he needs and
> he doesn't have to spend as much time learning things he won't really
> need (improving ones writing skills takes enough learning time).

I don't buy this kind of arguments. Most people nowadays spend *a lot*
of their time working with computers: many hours a day. And every
regular computer user will need to do some less common stuff now and
then. Some shell scripting skills will always pay off.


reply via email to

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