home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1997 March / Simtel-MSDOS-Mar1997-CD2.iso / 00_info / simgrep.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1997-01-27  |  2KB  |  69 lines

  1. #!/bin/sh
  2. #
  3. # simgrep -- search compressed Simtel.Net file list, and print findings
  4. #   with directory names
  5. #
  6. # <rreiner@nexus.yorku.ca>
  7. # Last revised Mon Feb  3 13:08:07 EST 1992
  8. #
  9.  
  10. #############################################################################
  11. # Customization section.
  12. #
  13. # The compressed file simibm.lst is stored in:
  14. COMPFILE=/usr/phil/grads/phigs/lib/simibm.zoo
  15. # The program it is to be uncompressed with:
  16. COMPPROG=zoo
  17. # The commandline switched needed to get COMPROG to extract a file to stdout:
  18. COMPFLAGS=xp
  19. # egrep:
  20. EGREPPROG=egrep
  21. # AWK:
  22. AWKPROG=nawk
  23. #
  24. # End of customization section.
  25. #############################################################################
  26.  
  27. MYNAME=`basename $0`
  28.  
  29. if [ $1z = z ]; then
  30.     echo "$MYNAME: usage is  $MYNAME expresssion."
  31.     echo "$MYNAME: note: searches are case-insensitive egrep regular expressions."
  32.     exit 1
  33. fi
  34.  
  35. #
  36. # The AWK contortions at the end of the pipe do the following:
  37. #
  38. #   Decide whether to print each line only when the next is encountered; then,
  39. #   if several "Directory PD" lines appear in sequence, keep only the last;
  40. #   precede each change of directory with a newline; and print everything
  41. #   that is not a "Directory PD" entry.
  42. #
  43. # The egrep and AWK stages of the pipe could be consolidated, but it is
  44. #   simpler and faster this way.
  45. #
  46. $COMPPROG $COMPFLAGS $COMPFILE | $EGREPPROG -i "Directory PD"\|"$1" \
  47.     | $AWKPROG '   { if (prevline == "") {
  48.             prevline = $0
  49.             next
  50.         }
  51.         if (prevline ~ "Directory PD") {
  52.             if ($0 ~ "Directory PD") {
  53.                 prevline = $0
  54.                 next
  55.             } else {
  56.                 print prevline
  57.                 prevline = $0
  58.             }
  59.         } else {
  60.             print prevline
  61.             prevline = $0
  62.             if ($0 ~ "Directory PD")
  63.                 print ""
  64.         }
  65.           }
  66.     END   { if (! (prevline ~ "Directory PD"))
  67.             print prevline
  68.           }'
  69.