home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!crdgw1!rdsunx.crd.ge.com!ariel!davidsen
- From: davidsen@ariel.crd.GE.COM (william E Davidsen)
- Newsgroups: comp.unix.shell
- Subject: Re: Splitting mail files
- Message-ID: <1993Jan22.231037.28718@crd.ge.com>
- Date: 22 Jan 93 23:10:37 GMT
- References: <1j1klhINNe05@roche.csl.sri.com> <1993Jan21.015928.1096@murdoch.acc.Virginia.EDU>
- Sender: usenet@crd.ge.com (Required for NNTP)
- Reply-To: davidsen@crd.ge.com (bill davidsen)
- Organization: GE Corporate R&D Center, Schenectady NY
- Lines: 44
- Nntp-Posting-Host: ariel.crd.ge.com
-
- How about a tiny awk script? It works with mailbox or article format,
- so it will handle articles saved out of news as well.
-
- ================================================================
- # splitshar - split a multipart posting into separate parts again
- #
- # call with
- # awk -f splitshar Fname=<name> <file>
-
- BEGIN {
- filenum = 0
- line1 = 1
- }
-
- # this is the first line, see if mailbox or article format
- line1 == 1 {
- # save the "start of article" string"
- matchstr = $1
- line1 = 0
- }
-
- # see if the start of a new article
- $1 == matchstr {
- if (filenum) close(filename)
- # make a new filename for this one
- filenum++
- filename = sprintf("%s%04d", Fname, filenum)
- print "Starting file " filename
- }
-
- # this is the default action, for all lines
- {
- print > filename
- }
-
- # status report
- END {
- if (filenum == 1) print "It was only one file"
- else printf("Saved in %d files\n", filenum)
- }
- ================================================================
- --
- bill davidsen, GE Corp. R&D Center; Box 8; Schenectady NY 12345
- Keyboard controller has been disabled, press F1 to continue.
-