home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD2.img / d4xx / d473 / cnewssrc / cnews_src.lzh / relay / sh / tear < prev   
Text File  |  1990-05-28  |  551b  |  26 lines

  1. #! /bin/sh
  2. # tear prefix [file...] - tear RFC822 header and body apart
  3. #    output files are $1hdr and $1body
  4. PATH=/bin:/usr/bin; export PATH
  5.  
  6. case $# in
  7. 0)
  8.     echo "usage: tear prefix [file...]" >&2
  9.     exit 1
  10.     ;;
  11. esac
  12.  
  13. hdr="$1hdr"
  14. body="$1body"
  15. shift
  16.  
  17. >>$hdr                    # create files just in case
  18. >>$body
  19. case $# in
  20. 0)    args="-" ;;    # awk needs a filename due to cmd. line assignments
  21. *)    args="$@" ;;
  22. esac
  23. exec awk 'inbody == 0 && ($0 ~ /^[^ \t]*:/ || ($0 ~ /^[ \t]/ && NR > 1)) { print >hdr; next }
  24.                     { inbody = 1; print >body }
  25. ' hdr="$hdr" body="$body" $args
  26.