Unix Power ToolsUnix Power ToolsSearch this book

21.5. Remove Mail/News Headers with behead

When you're saving or resending a Usenet article or mail message, you might want to the remove header lines (Subject:, Received:, and so on). This little script will handle standard input, one or many files. It writes to standard output. Here are a few examples:

mail Section 1.21

% behead msg* | mail -s "Did you see these?" fredf

Here's the script, adapted a little from the original by Arthur David Olson:

Figure Go to http://examples.oreilly.com/upt3 for more information on: behead

#! /bin/sh
case $# in
0)  exec sed '1,/^$/d' ;;
*)  for i
    do sed '1,/^$/d' "$i"
    done
    ;;
esac

The script relies on the fact that news articles and mail messages use a blank line to separate the header from the body of the message. As a result, the script simply deletes the text from the beginning up to the first blank line.

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.