[NCLUG] Find, grep and other pointy instruments
S. Luke Jones
luke at frii.com
Fri Apr 20 21:33:00 MDT 2001
Michael Dwyer wrote:
> I'm looking for a way to do this:
>
> find / -print | grep "everything unless it is a directory which
> includes a specific file"
Do you mean, find everything under / and whenever you find a
specific file you want to omit that entire directory, including
things that aren't the specific file?
find . -print | python foo.py
where foo.py looks like somewhat like this:
def main():
prev_dir = None
cached=[]
while 1:
ln = readline()
(dir,file) = quasi_basename_thing( ln )
if prev_dir == dir:
cached.append( file )
else:
for line in cached:
print prev_dir + '/' + line
cached = []
prev_dir = dir
def quasi_basename_thing( str ):
# this is an exercise for the student
# split 'str' like 'basename(1)' does on the final '/'
# return a tuple containing either side of the '/'
return (lhs,rhs)
This won't work so great when a directory contains a zillion entries
but that's another thread. (Maybe it was another LUG.) Also, it's
painful to split every single line.
So what the heck are you trying to do here, anyway, Michael?
--
Luke Jones = luke/vortex/frii/fullstop/com
More information about the NCLUG
mailing list