home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1203 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  1.8 KB

  1. From: jnelson@gauche.enet.dec.com (Jeff E. Nelson)
  2. Newsgroups: comp.sources.wanted,comp.lang.c,alt.sources
  3. Subject: Re: key word searches in text files
  4. Message-ID: <10384@shlump.nac.dec.com>
  5. Date: 18 Apr 90 21:01:51 GMT
  6.  
  7. [LEBF]
  8. In article <6109@ozdaltx.UUCP>, root@ozdaltx.UUCP (root) writes:
  9. > We maintain a large mass of text files on the board and I would like
  10. > for a caller to able to look for key works in those files  WITHOUT having
  11. > to use [e]grep to bang away at the files... This is the method we're
  12. > currently using.  It works, but is slow not to mention the wear and
  13. > tear on the HD.
  14.  
  15. How about simply creating an index file for each text file that you want
  16. indexed?  Because you mention "egrep" I assume you have Unix.  To create
  17. an index file, do this:
  18.  
  19. tr -cs A-Za-z '\012' | sort  -u
  20.  
  21. The 'tr' command breaks up the text file into a list of words, one per
  22. line.  The 'sort' command sorts the list with the '-u' flag removing
  23. duplicates.  Pipe the text file as input, pipe the output to an index
  24. file.  When someone wants to find out if a particular text file contains
  25. a keyword, search the index file corresponding to the text file.
  26.  
  27. This solution is simple and effecient:  (1) the index file only needs to
  28. be built once per text file, and (2) the index is optimized in that it
  29. contains only unique words, which saves wear and tear on your HD. 
  30. However, it may not be exactly what you need.  One drawback, for
  31. example, is that all you know is the existance of a keyword in a file;
  32. you don't know *where* in the file the keyword appeared.
  33.  
  34. If this isn't what you're looking for, then you'd better be more
  35. specific with what it is you want to accomplish.
  36.  
  37. -Jeff E. Nelson
  38. -Digital Equipment Corporation
  39. -Internet:  jnelson@tle.enet.dec.com
  40. -Affiliation given for identification purposes only.
  41.