home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5473 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.6 KB  |  58 lines

  1. Path: sparky!uunet!crdgw1!rdsunx.crd.ge.com!ariel!davidsen
  2. From: davidsen@ariel.crd.GE.COM (william E Davidsen)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Splitting mail files
  5. Message-ID: <1993Jan22.231037.28718@crd.ge.com>
  6. Date: 22 Jan 93 23:10:37 GMT
  7. References: <1j1klhINNe05@roche.csl.sri.com> <1993Jan21.015928.1096@murdoch.acc.Virginia.EDU>
  8. Sender: usenet@crd.ge.com (Required for NNTP)
  9. Reply-To: davidsen@crd.ge.com (bill davidsen)
  10. Organization: GE Corporate R&D Center, Schenectady NY
  11. Lines: 44
  12. Nntp-Posting-Host: ariel.crd.ge.com
  13.  
  14. How about a tiny awk script? It works with mailbox or article format,
  15. so it will handle articles saved out of news as well.
  16.  
  17. ================================================================
  18. # splitshar - split a multipart posting into separate parts again
  19. #
  20. # call with
  21. #    awk -f splitshar Fname=<name> <file>
  22.  
  23. BEGIN {
  24.   filenum = 0
  25.   line1 = 1
  26. }
  27.  
  28. # this is the first line, see if mailbox or article format
  29. line1 == 1 {
  30.   # save the "start of article" string"
  31.   matchstr = $1
  32.   line1 = 0
  33. }
  34.  
  35. # see if the start of a new article
  36. $1 == matchstr {
  37.   if (filenum) close(filename)
  38.   # make a new filename for this one
  39.   filenum++
  40.   filename = sprintf("%s%04d", Fname, filenum)
  41.   print "Starting file " filename
  42. }
  43.  
  44. # this is the default action, for all lines
  45. {
  46.   print > filename
  47. }
  48.  
  49. # status report
  50. END {
  51.   if (filenum == 1) print "It was only one file"
  52.   else printf("Saved in %d files\n", filenum)
  53. }
  54. ================================================================
  55. -- 
  56. bill davidsen, GE Corp. R&D Center; Box 8; Schenectady NY 12345
  57.     Keyboard controller has been disabled, press F1 to continue.
  58.