home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.admin
- Path: sparky!uunet!spool.mu.edu!caen!saimiri.primate.wisc.edu!zazen!zazen!bataller
- From: bataller@dogie.macc.wisc.edu (Erik Bataller)
- Subject: text searching CORRECTED
- Message-ID: <BATALLER.93Jan7180051@dogie.macc.wisc.edu>
- Sender: news@macc.wisc.edu (USENET News System)
- Organization: University of Wisconsin Academic Computing Center
- Distribution: comp.unix.questions,comp.unix.programmer,comp.unix.shell,comp.std.unix,comp.unix.bsd,comp.unix.misc,comp.sources.unix
- Date: 7 Jan 93 18:00:51
- Lines: 50
-
- Hello,
- I must apologize for my previous message about text searching.
- I know there are facilities for it like grep and find, but are there
- any good scripts or programs that do it nicely. For instance, included
- below is a script I tried to write which searches with find and grep
- so that I search recursively with getting all the ugly error messages
- grep spits out when you grep a directory. I am working to improve it.
- I just did it quickly and comments are more than welcome.
-
- Please except my apology and thanks in advance for any assistance.
-
-
- ______________________I call it searcher
- # C shell script to search for pattern in file(s)
- # in all files (argument 3- last)
- #
-
- switch ($#argv)
-
- #If only the pattern is given:
- case 1:
- find . -type f \( -name '*' -o -name '.*' \) -print | xargs grep -n "$argv[1]"
- breaksw
-
-
- #If the directory and the patter are given.
- case 2:
- find $argv[1] -type f \( -name '*' -o -name '.*' \) -print | xargs grep -n "$argv[2]"
- breaksw
-
-
- #If all the parameters are given:
- case 3:
- cd $argv[1] # change to dir in argument 1
- foreach file ( $argv[3-$#argv] )
- find . -type f -name "$file" -print | xargs grep -n "$argv[2]"
- breaksw
-
- #If no arguments are given
- default:
- echo "Usage: searcher [directory] [pattern] [file(s)]"
- exit 1
-
- endsw
- --
- !! Erik M. Bataller | Phone: (414) 242-0347 | Univ. of Wi., Osh Kosh
- !! Academic Computing Services | 800 Algoma Blvd., 307 Dempsey,
- !! Osh Kosh, Wi. 54901-8602 | Internet: Bataller@sol.acs.uwosh.edu
- !! Bitnet: Bataller@oshkoshw.bitnet
-
-