[comp.lang.perl] Need something to trim headers off of mail messages

tchrist@convex.COM (Tom Christiansen) (02/07/90)

In article <1990Feb6.153718.4546@eplrx7.uucp> mcneill@eplrx7.uucp (Keith McNeill) writes:
>Subject says most of it...
>
>I have something now called trim-headers ((C) 1986 Dave Taylor) but it gets
>a little carried away now & then....it trims off the entire message.

Well, if you accept that a "mail message" consists of a header and 
a body delimited by a blank line, a sed one-liner should do it:

    sed -n -e '/^$/,$p' files ...

Although ctually that gives you the blank line.  this one eats it

    sed -e '1,/^$/d' files ...

If you want to actually modify the file in-place, then
you might do something like this:

    foreach file ( files ... )
	sed -e '1,/^$/d' < $file  > $file.tmp && mv $file.tmp $file
    end

or as a one-liner in perl (you knew this was coming, right? :-)

    perl -i -n -e 'print unless 1../^$/;' files ...

or for the faint of heart desiring backup files: 

    perl -i.bak -n -e 'print unless 1../^$/;' files ...

and for the record, the keep-the-blank-line version is 

    perl -i -n -e 'print if /^$/..eof();' files ...

--tom
--

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"