help-octave
[Top][All Lists]
Advanced

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

Re: finding .m files using 'locate'


From: Mike Miller
Subject: Re: finding .m files using 'locate'
Date: Mon, 18 Jul 2005 23:51:09 -0500 (CDT)

On Mon, 18 Jul 2005, Przemek Klosowski wrote:

there's a mistake in your regexp:

  s#(^.*)/[^/]+.m#$1#g

the dot before the 'm' should be escaped (the result is OK, but it is
the kind of problems that trip up even seasoned regexp users).

You are right because I'm sure I mean to put a backslash in there, but I'm not sure that it does anything in this context (after "egrep '\.m$'"). In fact, I think this would work (dropping the ".m")...

s#(^.*)/[^/]+#$1#g

...because the first '*' is greedy so it takes up the full path.


Also, I believe your code would fail if there was a directory named /home/dir.m (so would mine, but for a different reason :)

I can't see why my code would fail. Can you explain that? This doesn't fail:

echo '/home/dir.m' | egrep '\.m$' | perl -pe 's#(^.*)/[^/]+.m#$1#g' | sort | 
uniq


I agree w/you completely about Perl being the only tool one ever needs ("Swiss army chainsaw"). I have eschewed sed, awk and even egrep; in fact I would have written your

locate .m | egrep '\.m$' | perl -pe 's#(^.*)/[^/]+.m#$1#g' | sort | uniq
as
locate .m | perl -ne 'print if s#(^.*)/[^/]+\.m$#$1#' | sort | uniq

Nice. You know more about this stuff than I do, I'm sure. (I do know I didn't need the 'g' but I didn't think of it.)

But remember the trick we learned about locate.  We can do this...

locate "*.m" | perl -pe 's#(^.*)/[^/]+m#$1#' | sort | uniq

...and leave off the grepping.

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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