#!/bin/sh fn=/tmp/$USER.$$ if [ $# -eq 0 ]; then cat > $fn elif [ $# -eq 1 ]; then if [ ! -f "$1" ]; then echo "Cannot access file $1" >&2 exit 1 else cat "$1" > $fn fi else echo "usage: mail_strip [ file ]" >&2 exit 1 fi set "a "`head -1 $fn | grep '^From [^ ]'` if [ $# -eq 1 ]; then echo "Not a mail file" >&2 rm -f $fn exit 1 fi nm=`grep '^From [^ ]' $fn | wc -l` while [ $nm -gt 1 ]; do em=`sed -n '1s/From \([^ ]*\).*/\1/p' $fn` echo "writing to $em" >&2 ed - $fn << EOF 1s/^// /^From [^ ]/,\$d W $em q EOF ed - $fn << EOF 1s/^// 1,/^From [^ ]/-1d w q EOF nm=`echo $nm - 1 | bc` done em=`sed -n '1s/From \([^ ]*\).*/\1/p' $fn` echo "writing to $em" >&2 cat $fn >> $em rm -f $fn