awk ' !/^$/ { blank=0; } /^From .*@/ { header++; maxlen = 0; next } /^###################$/ { header++; next; } /^[ ]*$/ { if (header) { print "" #From walker@opus Mon Jan 1 00:01:30 1994 #Date: Fri, 30 Nov 90 13:30:22 mst print "From rick_walker@opus.labs.agilent.com Tue Jan 2 12:34:56 2001" print date print from print "To: cp@opus.hpl.hp.com" print "Message-Id: " if (nsubj == 0) { #no subject in this header so use last one print "X" subj } else { print subj } header=0; nsubj=0; } maxlen = 0; if(++blank <= 1) { print } next; } /^Date:/ { date = $0 datex = date sub("Date: ","",datex) next; } /^XSubject:/ { nsubj++; subj = $0 subjx = subj sub("XSubject: ","",subjx) subj = "Subject: " subjx next; } /^Subject:/ { nsubj++; subj = $0 subjx = subj sub("Subject: ","",subjx) next; } /^From:/ { from = $0 fromx = from sub("From: ","",fromx) next; } // { if(header) { # discard extraneous header lines } else { print } next; } ' exit 0