home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 35.4 recomment: Clean Up Program Comment Blocks Chapter 35
You Can't Quite Call This Editing
Next: 35.6 Low-Level File Butchery with dd
 

35.5 Remove Mail/News Headers with behead

When you're saving or re-sending a news article or mail message ( 1.33 ) , 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:

  • With saved messages, at a shell prompt:

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

  • To save an article, from a pipe, without a header, from a program (here, the old readnews ) that can't cut off headers itself:

    What now? [ynq] 
    
    s- | behead >
    
     
    
    filename
    
    

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


#! /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 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


Previous: 35.4 recomment: Clean Up Program Comment Blocks UNIX Power Tools Next: 35.6 Low-Level File Butchery with dd
35.4 recomment: Clean Up Program Comment Blocks Book Index 35.6 Low-Level File Butchery with dd

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System