Article 3334 of comp.lang.perl: Xref: feenix.metronet.com comp.lang.perl:3334 Newsgroups: comp.lang.perl Path: feenix.metronet.com!news.ecn.bgu.edu!wupost!spool.mu.edu!sgiblab!adagio.panasonic.com!chorus.mei!oskgate0.mei!wnoc-kyo!sh.wide!wnoc-tyo-news!sranha!sranhd!sran230!utashiro From: utashiro@sran230.sra.co.jp (Kazumasa Utashiro) Subject: Re: Directory Grep?? References: <1993Jun10.143017.25932@rtsg.mot.com> Organization: Software Research Associates, Inc., Japan Date: Fri, 11 Jun 1993 02:06:22 GMT Message-ID: Lines: 70 In article <1993Jun10.143017.25932@rtsg.mot.com> ellis@rtsg.mot.com (John T Ellis) writes: >> Has anyone implemented a directory grep in perl? My ideal >> view of the tool includes - >> >> - Ability to handle multiple (controlled by an option ie. -l) >> levels of directories >> >> - Ability to handle multiple (controlled by an option ie. -s) >> levels of symbolic links >> >> - Ability to exclude certain directories from being searched >> (-i ??) >> >> - Ability to accept wildcards in the file specification >> >> - Ability to designate starting directory (-d ??) >> >> Therefore, to do a directory search for the word 'perl' starting in /usr/lib, >> descending 3 sub-directory levels, allowing only 2 levels of symbolic links, >> and not searching the any directory named 'tmp' you would do the following: >> >> dgrep -l 3 -s 2 -i 'tmp' -d /usr/lib perl* >> >> Does something like this (or any other variation thereof) exist? My mg supports some of them. Here is directory related options list. usage: mg [ -options ] pattern [ file... ] ... -R search recursively -P pattern specify search file in wildcard (w/-R) -V pattern specify exception file in wildcard (w/-R) -F follow symbolic link of directory (w/-R) ... You can use it like this. mg -RV tmp perl /usr/lib This morning, I added an option to specify descending directory level in one minute and it seems to work pretty well. So I included it as a feature but the interface may change in the near future. Currently, you can use it like this. mg -RV tmp -D3 perl /usr/lib There is no option to handle levels of symbolic link. Option -F specifies follow directory symlink or not, but symlink for a file is always followed. MG is available from srawgw.sra.co.jp:pub/lang/perl/sra-scripts I'm thinking to post again it here because it has been improved much after last posting. Does anybody want it? ;# EXAMPLES: ;# % mg 'control message protocol' rfc*.txt.Z # line across search ;# % mg -nRTP '*.[sch]' 'struct vnode' /sys # recursive search ;# % mg -o sockaddr /usr/include/sys/socket.h # paragraph mode ;# % mg -Bc0,1 '@(#)' /lib/libc.a # binary mode ;# % mg -iTB copyright /bin/* # auto bin/text mode ;# % tset -IQS | mg -ec0 '(so|se)=[^:]+' # matched part only ;# % echo $path | mg -Q mh # highlighting --utashiro