From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,9e32d0119366ce3c X-Google-Attributes: gidfee84,public From: alan@nabeth.cxo.dec.com (Alan Rollow - Dr. File System's Home for Wayward Inodes.) Subject: Re: UNIX command to search subdirs for text in a file Date: 1997/01/14 Message-ID: <5bh1hf$5ur@nntpd2.cxo.dec.com>#1/1 X-Deja-AN: 210011273 distribution: world references: <01bc018d$8f170bc0$17ee1bac@usbgrjeff> organization: Digital Equipment Corporation reply-to: alan@nabeth.cxo.dec.com (Alan Rollow - Dr. File System's Home for Wayward Inodes.) newsgroups: comp.unix.osf.osf1 In article <01bc018d$8f170bc0$17ee1bac@usbgrjeff>, "Jeff Shervey" writes: > >With DEC UNIX 3.2 how can I search a bunch of subdirectories for a certain >file that contains certain text. find . -name '*.sql' -print | xargs grep -i duplicate /dev/null Starting at the current directory, find search for all the files with names of the form .sql and print the names to stdout. This is written a copy xargs which collects as many names as will fit on a command line and executes the command "grep -i ..." with that file list. The use of /dev/null as the first name of the name ensures that grep will always print the file name, since it typically doesn't if there is only one file name in the list. THere may be a grep option to provide this feature. If you're interested in what your commands were actually trying to do... >I'm trying this command with no luck: > >grep -i "duplicate" | find . -name *.sql -print Do an case insensitive search for the string duplicate reading from stdin and pipe that to the indicated find command. Not that find ever reads anything from stdin. > >I've also tried: > >find . -name *.sql -print | grep -i "duplicate" *.pls Find all the indicated names and write them to grep's stdin. Were it not for the *.pls, this would search the file *names* for the text "duplicate". But since this grep has been handed a file wildcard of *.pls, that will be expanded by the shell and those files will be used instead of the text from stdin. It is also worth noting that the sequence "-name *.sql" won't search for the names of the form .sql. The shell does the expansion of *.sql so the -name option will get the first of that expansion and the rested will be treated by find as options, which it will probably complain about. For example, if you had a.sql and b.sql, find would see: find . -name a.sql b.sql -print By quoting '*.sql' the shell won't expand it and find will know what to make of the wildcard. > >Thank you, >jeff.shervey@us.landisstaefa.com > >-- >These comments do not necessarily reflect the views of Landis & Staefa, Inc. > -- Alan Rollow alan@nabeth.cxo.dec.com