Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.arch Subject: Re: Globbing Message-ID: <10803@dog.ee.lbl.gov> Date: 11 Mar 91 09:35:54 GMT References: <1991Feb18.152347.28521@dgbt.doc.ca> <474@bria> <19217@cbmvax.commodore.com> <5573:Feb2307:19:4491@kramden.acf.nyu.edu> <00085@meph.UUCP> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 80 X-Local-Date: Mon, 11 Mar 91 01:35:54 PST (Sigh, I had hoped my observation that `what works in one system is not necessarily appropriate/best for all' would end this, but...:) In article <00085@meph.UUCP> gsarff@meph.UUCP writes: >Sorry for the diatribe ... I am not going to disagree with your general idea, but you really should get the details right when you post something like this: >Example 1: >WMCS: > wscan *.c include*.h >UNIX: > grep include\*.h *.c > > Which is easier, or more intuitive? Which is more powerful? :-) Your grep command searches for `includ', followed by zero or more `e's followed by any character except newline, followed by `h'. You probably meant grep 'include.*\.h' *.c Grep-style regular expressions are more powerful than shell metacharacters, at the expense of more complexity. Note that, with back-references, grep can be tricked into context-sensitive matches such as the one that pulled the following words from the dictionary: % grep '^\(.*\)\1$' /usr/share/dict/web2 [actually, I cheated, the command I used was grep '^\(.*\)\1$' /usr/share/dict/web2 | rsh horse.ee.lbl.gov 'cat >tmp' since these boxes are running SunOS and do not have a web2. I then deleted all but 27 words and ran these through `pr -3 -t -l9' to get a column sort.] atlatl coco furfur beriberi couscous gabgab bonbon cuscus gogo bulbul dada grigri cancan dodo grisgris caracara dumdum grugru chichi enaena guitguit chocho eyey gulgul chowchow froufrou juju I will not argue grep's ease of use, but I would not give up much (if any) of its power. >Example 2: >[directory with >24000 files] ... The best unix could do was print >"Command line too long", because I had used * for file wildcarding. This has been fixed in some Unixes, and will be fixed in others. >Example 3: > ... I want to do the same scan on the entire disk, > so for the two OS's we get the following: > >wscan /*/*.c include*.h (Does /*/ really mean `all directories' and not `the top level'? If so, how do you restrict the number of levels searched?) >Unix: >probably something like a shell loop or using find >find / -name \* -exec grep include\*.h \{\} \; Actually: find / -name '*.c' -exec grep 'include.*\.h' {} \; or (given arbitrarily long argument lists): grep 'include.*\.h' `find / -name '*.c' -print` Eschew backslash: quotes are your friends.... -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov