How to apply sed script only to headers of email?
This script strips the timezone from an email's Date 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 don't want the timezone stripped if a date appears in the body of the email. How can I get sed to quit after a double newline is encountered (signaling the end of the email header fields)? How can I apply substitutions only to the header of an email? Is this possible in sed? An awk solution would also be acceptable.
update:
I figured out how to quit sed like I wanted by matching an empty line:
/^$/q
However, I didn't really want开发者_运维知识库 to quit because the body of the email is not printed, then.
You probably can do this using the branch functionality and have the branch do normal printing. /^$/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
Of course if I were doing this for real I would use perl.
精彩评论