Thread View: alt.lang.awk
1 messages
1 total messages
Started by william E Davidsen
Tue, 02 Mar 1993 16:53
AWK: split multiple messages from a mail file
Author: william E Davidsen
Date: Tue, 02 Mar 1993 16:53
Date: Tue, 02 Mar 1993 16:53
76 lines
2328 bytes
2328 bytes
Someone asked the other day for a program to split shar files, or
asked for a repost, or some such. This is a little awk program to do the
job, one I use regularly, since I tend to dump all the parts of a source
in one file and fight with it later.
I tried to post this a few days ago, and it didn't *seem* to go out so
I'm reposting. If you've seen it before and you're ungenerous, please
flame by mail.
# splitshar - split a multipart posting into separate parts again
#
# call with
# awk -f splitarch.awk <file>
BEGIN {
filenum = 0
line1 = 1
header = "splitarch.hdr"
outfile = header
filename = outfile
pending = 0 # have no archive pending
}
line1 == 1 {
# save the "start of article" string"
matchstr = $1
line1 = 0
}
$1 == matchstr {
if (filenum) {
close(filename)
printf(" %d lines\n", Lines);
}
# go back to the hdr file
filename = header
filenum++
pending = 0
}
# find an Archive-name: header line
/^Archive-name:/ {
pending = 1
p_filename = $2
dir = p_filename
sub("/.*$", "", dir)
printf("File: %s", p_filename)
}
# Here's where we pick up the end of header
/^ *$/ {
if (pending) {
pending = 0
filename = p_filename
Lines = 0
}
}
# this is the default action, for all lines
{
print > filename
++Lines
}
END {
printf(" %d lines\n", Lines)
if (filenum == 1) print "It was only one file"
else printf("Saved in %d files\n", filenum)
close(outfile)
printf("mv %s %s/\nls -l %s", header, dir, dir) | "sh"
}
--
bill davidsen, GE Corp. R&D Center; Box 8; Schenectady NY 12345
Windows NT is a *great* program!
It's everything CP/M should have been all along.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads