DragonFly kernel List (threaded) for 2008-02
DragonFly BSD
DragonFly kernel List (threaded) for 2008-02
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Globbing

From: "Simon 'corecode' Schubert" <corecode@xxxxxxxxxxxx>
Date: Thu, 14 Feb 2008 12:06:53 +0100

Rahul Siddharthan wrote:
For example, how do you use "find" to find all files in a directory
that end in ".el" and don't have a corresponding ".elc" file? Answer:
find . -name '*.el' -print \
|sed 's/^/FOO=/' \
|sed 's/$/; if [ ! -f ${FOO}c ]; then echo $FOO; fi/' \
| sh

When I want to do something like that to a large directory, I generate
a full directory listing and then write a python program to parse it.
That seems easier to wrap my mind around.  (The author of the above
find command used emacs-lisp instead, then figured out the correct
find incantation because it bothered him.  "It only took me 12 tries
to get it right.  It only spawns two processes per file in the
directory tree we're iterating over.  It's the Unix Way!")

No doubt Simon or someone will now point out a trivial one-line
invocation of find that will do the job and will be obvious to anyone
who understands the find manpages.

I'd go for (if only in the current directory, not subdirs)

for f in *.el
	[ -f "${f}c" ] || echo "$f"

likewise, with find for subdirs (not POSIX):

find . -name '*.el" -exec sh -c 'for f; do [ -f "${f}c" ] || echo "$f"; done' dummy {} +

I don't think that shows how awkward unix is. I bet you could find tasks which need much more stupid hacks.


Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \

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