removing header lines
coleman%nrl-aic at sri-unix.UUCP
coleman%nrl-aic at sri-unix.UUCP
Sat Jun 18 01:06:00 AEST 1983
From: Jeff Coleman <coleman at nrl-aic>
Below is a header-line filter that only deletes lines in the header,
i.e., lines between the beginning of the message and the first blank
line. Works on a single message or file of messages preceded by a
line containing only SEPARATOR (edit to reflect your preference--I use
control-C). It is faster than a less-powerful awk version I used for a
while. Tested on a 4.1bsd system.
The separator is treated as a not-to-be-deleted header line.
Consequently, a separator preceding the first message is left intact
while a separator following the last message looks like an incomplete
one-line message and is deleted. A blank line after the trailing
separator makes it a complete "header" and will cause the separator to
be undisturbed.
--------------------------------------------------
#! /bin/sh
# Filter to remove undesired header lines from a message or a file of
# SEPARATOR-preceded messages. As a side effect, it compresses
# multiple-line header fields into a single line.
# Jeff Coleman 6/17/83
# coleman at nrl-aic
# At the top of ":Loop" the previous input line, no part of which has been
# printed, is in the hold space. It may be a compounded line. At ":Break"
# the hold space holds a copy of the current input line and the pattern
# space contains the current input line catnenated with the previous
# (possibly compound) input line. The previous part is printed if
# appropriate.
sed \
'1,/^$/bHead
/^SEPARATOR$/,/^$/{
:Head
1bLine1
/^SEPARATOR$/{
:Line1
h
d
}
:Loop
H
x
s/[ ]*\n[ ][ ]*/ /
tMore
bBreak
:More
h
d
bLoop
:Break
/^From / bFinish
/^Message-I[Dd]: / bFinish
/^In-[Rr]eply-[Tt]o: / bFinish
/^Origin: / bFinish
/^Remailed-[Ff]rom: / bFinish
/^Remailed-[Dd]ate: / bFinish
/^Remailed-[Tt]o: / bFinish
/^Mail-[Ff]rom: / bFinish
/^Via: / bFinish
/^Return-[Pp]ath: / bFinish
/^Received: / bFinish
/^Article-I.D.: / bFinish
/^Sender: / bFinish
/^Reply-[Tt]o: / bFinish
/^Resent-[Dd]ate: / bFinish
/^Re[Ss]ent-[Ff]rom: / bFinish
/^Resent-Message-Id: / bFinish
/^Re[Ss]ent-[Tt]o: / bFinish
/^Fcc: / bFinish
/^Forwarded: / bFinish
/^Newsgroups: / bFinish
/^Phone: / bFinish
/^Posted-Date: / bFinish
/^[Rr]e: / bFinish
P
:Finish
/\n$/{
g
p
}
d
}' \
$1
More information about the Comp.unix.wizards
mailing list