home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / filedocs / simgrep2.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1994-03-04  |  2KB  |  80 lines

  1. #!/bin/sh
  2. #
  3. # simgrep -- search compressed SimTel file list (from simlist.zip), and
  4. #            print findings with directory names
  5. #
  6. # <rreiner@nexus.yorku.ca>
  7. #
  8. # Revised:
  9. #   Mon Feb  3 13:08:07 EST 1992
  10. #   Wed Oct  6 17:41:52 EDT 1993 -- changed to match new listing format
  11. #   Thu Oct 21 19:18:51 EDT 1993 -- cleaned up.
  12. #
  13.  
  14. ##
  15. ## Copyright (C) 1992 Richard Reiner, all rights reserved.
  16. ##
  17.  
  18. #############################################################################
  19. # Customization section.
  20. #
  21. # The compressed file the SimTel file index is stored in:
  22. COMPFILE=/usr/phil/grads/phigs/lib/simlist.zip
  23. # The program it is to be uncompressed with:
  24. COMPPROG=unzip
  25. # The commandline switches needed to get COMPROG to extract a file to stdout:
  26. COMPFLAGS=-p
  27. # The name of the index file within COMPFILE:
  28. INDEXFILE=SIMIBM.LST
  29. # egrep:
  30. EGREPPROG=egrep
  31. # AWK:
  32. AWKPROG=nawk
  33. #
  34. # End of customization section.
  35. #############################################################################
  36.  
  37. MYNAME=`basename $0`
  38.  
  39. if [ $1z = z ]; then
  40.     echo "$MYNAME: usage is  $MYNAME expresssion."
  41.     echo "$MYNAME: note: searches use case-insensitive egrep regular expressions."
  42.     exit 1
  43. fi
  44.  
  45. #
  46. # The AWK contortions at the end of the pipe do the following:
  47. #
  48. #   Decide whether to print each line only when the next is encountered; then,
  49. #   if several "Directory" lines appear in sequence, keep only the last;
  50. #   precede each change of directory with a newline; and print everything
  51. #   that is not a "Directory" entry.
  52. #
  53. # The egrep and AWK stages of the pipe could be consolidated, but it is
  54. #   simpler and faster this way.
  55. #
  56. $COMPPROG $COMPFLAGS $COMPFILE $INDEXFILE | $EGREPPROG -i "^Directory"\|"$1" \
  57.     | $AWKPROG '   { if (prevline == "") {
  58.             prevline = $0
  59.             next
  60.         }
  61.         if (prevline ~ "^Directory") {
  62.             if ($0 ~ "^Directory") {
  63.                 prevline = $0
  64.                 next
  65.             } else {
  66.                 print prevline
  67.                 prevline = $0
  68.             }
  69.         } else {
  70.             print prevline
  71.             prevline = $0
  72.             if ($0 ~ "^Directory")
  73.                 print ""
  74.         }
  75.           }
  76.     END   { if (! (prevline ~ "^Directory"))
  77.             print prevline
  78.           }'
  79.  
  80.