How to apply sed script only to email headers?

This script splits the time zone from email fields:

#!/bin/sed -rf
s/(^Date: (Sun|Mon|Tue|Wed|Thu|Fri|Sat),.*[0-9][0-9]:[0-9][0-9]:[0-9][0-9]) \+0900$/\1/i

However, I do not want the time zone to be split if a date appears in the body of the message. How can I get sed to exit after a double newline occurs (signaling the end of the email header fields)? How can I apply replacements only to the email header? Is this possible in sed? Awk solution would also be acceptable.

update:

I figured out how to exit sed as I wanted by matching an empty string:

/^$/q

However, I really did not want to leave, because the body of the letter is not printed.

+3
source share
1 answer

, , . /^$/b x

#!/bin/sed -rf
x
/^MAGICTOKEN$/b body
x
s/(^Foo: bar).*/\1/i
p
s/^$/MAGICTOKEN/
/^MAGICTOKEN$/x
d

: body
x
p
d

, -, perl.

+1

All Articles