awk print the body of an email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk print the body of an email
# 1  
Old 06-17-2012
awk print the body of an email

I have fetched a couple of emails and stored then in /fetch/mail/oracle.txt, the displayed content is

Code:
Date:
From:
Subject:
To:
Content-Type:
---body -----
---------
Date:
From:
Subject:
To:
Content-Type:
----body -----
------
Date:
From:

I want to retrieve the body only from the emails i fetched,the problem i am having is the body doesn't have a tag,

the output should be like
Code:
email-1
----body---
email-2
----body---


Last edited by Scrutinizer; 06-17-2012 at 05:14 AM.. Reason: code tags
# 2  
Old 06-17-2012
Awk

Hi,

Try this one,
Code:
awk '/Content-Type/{p=1;c++;print "Email-",c;}/Date/{p=0}p' file

Cheers,
Ranga:-)

Last edited by rangarasan; 06-17-2012 at 04:24 PM..
# 3  
Old 06-17-2012
Thank you
# 4  
Old 06-17-2012
Lookout for body text that contains "date" (a fairly common word).

This might be a little safer:
Code:
awk '/^Content-Type:/{p++;$0="Email-" ++c}/^----/{p=0}p' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mutt command email body

Hi Team, While sending the email using the mutt command, mail body not appearing properly and attachment it is showing without line breaks and i used the CSS Style (nowrapper )it is working fine. in this case how to handle the email body, please help me. (1 Reply)
Discussion started by: bmk123
1 Replies

2. UNIX for Beginners Questions & Answers

Not able to generate table in email body

Below is the code snippet and I'm not able to generate the table in email, output email has nothing if ; then echo "File $fName exists." awk -F "," ' BEGIN { print "MIME-Version: 1.0" print "Content-Type: text/html" print "Subject: Out OF Network Fee - Portfolio Level Stats" print... (1 Reply)
Discussion started by: vyomdev
1 Replies

3. Shell Programming and Scripting

Recursive header for email body

i have added the header also to the script you provided, it is working fine, but I am expecting to get the header over those rows for which the URL or port changes. URL will remain same for few rows and then it change, and once the URL change the header should come, like in below input you can see... (11 Replies)
Discussion started by: mirwasim
11 Replies

4. Shell Programming and Scripting

Need special charecter in email body

I have a unix shell script generate.sh that writes to a file hello.txt using redirect. For example:echo " Today's report shows progress by: " > hello.txt This hello.txt is then send as an email body to the recipients. My requirement is to have this special characters(up arrow and down arrow... (6 Replies)
Discussion started by: mohtashims
6 Replies

5. UNIX for Advanced & Expert Users

Bold letter in email body

Hi All, The below is the email text and i want few words in BOLD. I am writing the below message in to a .txt file and calling it in a function which generated email. when i run at cmd prompt it is working fine , but wehn i run a script .sh it is not working. Below is the text printing in to... (2 Replies)
Discussion started by: kiranparsha
2 Replies

6. Shell Programming and Scripting

issue with Email Body

Hi, I have written shell program to send email as below - #!/bin/ksh filename=`ls -ltrh *.Z` echo $filename |mailx -s "FOR TESTING" rahul.b@infotech.net I am getting the email but email body is - -rw-rw-r-- 1 bahulra dba 173M Mar 22 04:37 corphist.txt.Z -rw-rw-r-- 1 bahulra dba 107M... (3 Replies)
Discussion started by: rahulbahulekar
3 Replies

7. Shell Programming and Scripting

Crontab issue: getting email but with out body

I have a oracle sh script test.sh #!/bin/bash R=`sqlplus -S *****/*********@dfsdf <<ENDOFSQL set serveroutput on size unlimited; execute DBMS_SNAPSHOT.REFRESH( '"MIS_ADMIN"."MV_SURVEY_UNITS_CENSUS"','F'); execute DBMS_SNAPSHOT.REFRESH( '"MIS_ADMIN"."MV_SURVEY_UNITS_CENSUS_PART"','F');... (1 Reply)
Discussion started by: ramkia6
1 Replies

8. Shell Programming and Scripting

The body of the Email -- mailx

Hi, I am using mailx command to send an email and i took the body of the email from a file, mailx -r gtt.org -s "Status Report " ss@org.com < $ProcessStatisticsFile but now i want to declare the body of the email in the command itself. I have tried with the following command but... (4 Replies)
Discussion started by: chinnu01
4 Replies

9. Shell Programming and Scripting

emailing as body of email

hi all, how do i email a file in the body of an email rather than as an attachment ?? have a ksh script which i need to read a file and email as part of the body rather than an attachment. my code is : uuencode file.log | mailx -s "test" but this sends file as an attachment. ... (2 Replies)
Discussion started by: cesarNZ
2 Replies

10. Shell Programming and Scripting

how to check body of the email

Dears, i have user called dellsh i hope to make this script when this user recieve email check the budy of the email about (StatusRequest) when i find this email contain this subject run crontab do this job (create file in my home directory called index) thanks for your attention (1 Reply)
Discussion started by: dellsh
1 Replies
Login or Register to Ask a Question