HELP with awk and sed to parse email 
Author Message
 HELP with awk and sed to parse email

I need assistance with an awk or sed script that will parse an email in
unix.  I need it to pull "To:" From:"
and Subject: information.  I also want to discard any attachments since unix
can't use them anyway..
I know someone has already tackled this assignment.

Please help!!!!

Thanks in advance.



Tue, 05 Jun 2001 03:00:00 GMT  
 HELP with awk and sed to parse email

Quote:

>I need assistance with an awk or sed script that will parse an email in
>unix.  I need it to pull "To:" From:"
>and Subject: information.  I also want to discard any attachments since unix
>can't use them anyway..
>I know someone has already tackled this assignment.

>Please help!!!!

>Thanks in advance.

awk '/^To:/ || /^From:/ || /^Subject:/' infile > outfile

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 05 Jun 2001 03:00:00 GMT  
 HELP with awk and sed to parse email

Quote:

> awk '/^To:/ || /^From:/ || /^Subject:/' infile > outfile

That's a start, but to do the job correctly, the script should terminate after the
headers, i.e. at the first empty line. As written, the script will echo lines that
happen to begin with "To:", etc. even though they appear within the body of the
message.


Tue, 05 Jun 2001 03:00:00 GMT  
 HELP with awk and sed to parse email


Quote:

>> awk '/^To:/ || /^From:/ || /^Subject:/' infile > outfile

>That's a start, but to do the job correctly, the script should terminate
>after the headers, i.e. at the first empty line. As written, the script
>will echo lines that happen to begin with "To:", etc. even though
>they appear within the body of the message.

OK:

awk '/^To:/ || /^From:/ || /^Subject:/;/^$/ {exit}' infile > outfile

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 05 Jun 2001 03:00:00 GMT  
 HELP with awk and sed to parse email


Quote:

>> awk '/^To:/ || /^From:/ || /^Subject:/' infile > outfile

>That's a start, but to do the job correctly, the script should terminate after the
>headers, i.e. at the first empty line. As written, the script will echo lines that
>happen to begin with "To:", etc. even though they appear within the body of the
>message.

awk '/^(To|From|Subject):/ { print }
/^$/ { exit }' infile > outfile

Should work OK in normal shells.  In csh, add a \ to the end of the
first line.
--
Steve



Wed, 06 Jun 2001 03:00:00 GMT  
 HELP with awk and sed to parse email

Quote:




>>> awk '/^To:/ || /^From:/ || /^Subject:/' infile > outfile

>>That's a start, but to do the job correctly, the script should terminate
>>after the headers, i.e. at the first empty line. As written, the script
>>will echo lines that happen to begin with "To:", etc. even though
>>they appear within the body of the message.

>OK:

>awk '/^To:/ || /^From:/ || /^Subject:/;/^$/ {exit}' infile > outfile

Sometimes mail stored in a file starts with a blanl line.

If the first line(s) may be blank, then, it could be done like this:

awk '/^(To|From|Subject):/{c++;print};c>0&&/^$/{exit}' infile > outfile

I wanted to fit it all on one line, so I modified my former method. :-)

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Wed, 06 Jun 2001 03:00:00 GMT  
 HELP with awk and sed to parse email


Quote:

>> awk '/^To:/ || /^From:/ || /^Subject:/;/^$/ {exit}' infile > outfile

>Why not

>awk '/^To:/; /^Subject:/; /^From::/{ print; exit }' infile > outfile

                                  ^????

I'm not sure, must they be in a certain order, and must From: exist?
I'll leave it for someone else to read RFC822 (I think that's the
one dealing with email).

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Thu, 07 Jun 2001 03:00:00 GMT  
 HELP with awk and sed to parse email

Quote:

> awk '/^To:/ || /^From:/ || /^Subject:/;/^$/ {exit}' infile > outfile

Why not

awk '/^(To|Subject):/; /^From:/{ print; exit }' infile > outfile

?
LMS



Fri, 08 Jun 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Need help with sed or awk !!

2. Need awk (or sed) help PLEASE!

3. sed/awk - grabbing column/pos help!!

4. new to sed/awk, need help badly

5. help with awk/sed, please

6. Sed/Awk help needed

7. sed parsing

8. Newbie awk (sed??) question, regular expressions

9. Awk/Sed Filehandler question

10. sed, awk, perl

11. A very simple question on SED or AWK for a GURU, and an enjoyable problem

12. SED to AWK...???

 

 
Powered by phpBB® Forum Software