home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume9 / elm2 / part01 / utils / trim-headers < prev   
Encoding:
Text File  |  1987-03-08  |  1.2 KB  |  55 lines

  1. : Use /bin/sh
  2.  
  3. # This shell script is designed to be used either to trim the 'junk' headers
  4. # out of an archived/saved mailbox file or to trim the headers off a file 
  5. # that is being piped to it.  The program considers the following headers
  6. # to be worth saving - everything else is junked.
  7. #
  8. #    From <user> <date>
  9. #    From: name <address>
  10. #    Subject:
  11. #    To: 
  12. #    Cc:
  13. #    Date:
  14. #
  15. # all others are ignored and trashed.
  16. #
  17. # (C) Copyright 1986, Dave Taylor
  18.  
  19. # first off, let's make the 'awk' script we'll be using...
  20.  
  21. cat << 'END_OF_AWK_SCRIPT' > /tmp/awk.$$
  22. BEGIN { in_body = 1 }
  23. {    if (in_body) {
  24.       if ($1 == "From") in_body = 0;
  25.       print $0
  26.     }
  27.     else if ($1 == "From:" || $1 == "Subject:" || $1 == "To:" || \
  28.              $1 == "Cc:" || $1 == "Date:")
  29.       print $0
  30.     else if (length($0) == 0) {
  31.       in_body = 1;
  32.       print $0
  33.     }
  34. }
  35. END_OF_AWK_SCRIPT
  36.  
  37. # next let's see if we're being piped to or if we've been handed
  38. # either a file name or list of file names...
  39.  
  40. if [ "$1" = "" ]
  41. then
  42.   cat - | awk -f /tmp/awk.$$ | uniq
  43.   rm -f /tmp/awk.$$
  44. else
  45.   for filename in $*
  46.   do
  47.     echo filtering file $filename
  48.     cat $filename | awk -f /tmp/awk.$$ | uniq > OUTFILE
  49.     mv OUTFILE $filename
  50.   done
  51.   echo done
  52. fi
  53.   
  54. exit 0 
  55.