home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / admin / 6968 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.0 KB  |  62 lines

  1. Newsgroups: comp.unix.admin
  2. Path: sparky!uunet!spool.mu.edu!caen!saimiri.primate.wisc.edu!zazen!zazen!bataller
  3. From: bataller@dogie.macc.wisc.edu (Erik Bataller)
  4. Subject: text searching CORRECTED
  5. Message-ID: <BATALLER.93Jan7180051@dogie.macc.wisc.edu>
  6. Sender: news@macc.wisc.edu (USENET News System)
  7. Organization: University of Wisconsin Academic Computing Center
  8. Distribution: comp.unix.questions,comp.unix.programmer,comp.unix.shell,comp.std.unix,comp.unix.bsd,comp.unix.misc,comp.sources.unix
  9. Date: 7 Jan 93 18:00:51
  10. Lines: 50
  11.  
  12. Hello,
  13.     I must apologize for my previous message about text searching.
  14. I know there are facilities for it like grep and find, but are there
  15. any good scripts or programs that do it nicely.  For instance, included
  16. below is a script I tried to write which searches with find and grep
  17. so that I search recursively with getting all the ugly error messages
  18. grep spits out when you grep a directory.  I am working to improve it.
  19. I just did it quickly and comments are more than welcome.
  20.  
  21. Please except my apology and thanks in advance for any assistance.
  22.  
  23.  
  24. ______________________I call it searcher
  25. # C shell script to search for pattern in file(s)
  26. # in all files (argument 3- last)
  27.  
  28. switch ($#argv)
  29.  
  30.     #If only the pattern is given:
  31.     case 1:
  32.         find . -type f \( -name '*' -o -name '.*' \) -print | xargs grep -n "$argv[1]"
  33.         breaksw
  34.  
  35.  
  36.     #If the directory and the patter are given.
  37.     case 2:
  38.         find $argv[1] -type f \( -name '*' -o -name '.*' \) -print | xargs grep -n "$argv[2]"
  39.         breaksw
  40.  
  41.  
  42.     #If all the parameters are given:
  43.     case 3:
  44.         cd $argv[1]    # change to dir in argument 1
  45.         foreach file ( $argv[3-$#argv] )
  46.         find . -type f -name "$file" -print | xargs grep -n "$argv[2]" 
  47.         breaksw
  48.  
  49.     #If no arguments are given
  50.     default:
  51.         echo "Usage:  searcher [directory] [pattern] [file(s)]"
  52.         exit 1
  53.  
  54. endsw
  55. --
  56. !!  Erik M. Bataller | Phone: (414) 242-0347 | Univ. of Wi., Osh Kosh 
  57. !!  Academic Computing Services | 800 Algoma Blvd., 307 Dempsey, 
  58. !!  Osh Kosh, Wi. 54901-8602 | Internet: Bataller@sol.acs.uwosh.edu 
  59. !!  Bitnet: Bataller@oshkoshw.bitnet
  60.  
  61.