The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
call shell script from perl cgi script problem raksha.s Shell Programming and Scripting 2 03-25-2009 04:50 AM
Call a perl script inside a shell script chriss_58 Shell Programming and Scripting 3 12-01-2008 04:28 AM
Include PERL script with in the unix shell script ganapati UNIX for Dummies Questions & Answers 1 04-29-2008 01:18 PM
How to Run a shell script from Perl script in Parent shell? hifake Shell Programming and Scripting 16 08-28-2007 09:42 PM
Looping a perl script in a shell script edkung Shell Programming and Scripting 8 10-04-2002 11:28 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-22-2009
terry2009 terry2009 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 11
Perl script to shell ???

Hi,

I have a log file containing data on emails sent. Looks a bit like this for one email:

Code:
Content-Type: text/plain;
charset="UTF-8"
Date: 12 Jun 2008 14:04:59 +0100
From: from@email.com
Subject: xcf4564xzcv
To: recip@email.co.uk
Size = 364 Jun 12 14:04 smtp_234sldfh.tmp

I need to take the subject, date, time, size and To: and stick it in an output file in the following format

Code:
1,recip@email.co.uk,1,,,1,xcf4564xzcv,1,12 Jun 2008,14:04:59,1,,364

How can I do this in Shell (AIX)... sed? grep? Here is the perl script I wrote:

Code:
open(READLOGFILE, "C:\\temp\\email.log") or die("Failed to open file");
open(WRITELOGFILE, ">>C:\\temp\\emailstats.log") or die("Failed to open file");
$numRecords = 0;
$emailSize = 0;
$foundSize = 0;
$foundEmail = 0;
$foundSubject= 0;
$foundDate = 0;
while($line = <READLOGFILE>) {
if($line =~ /^Subject\:\s(\S*)/ ) {
$subject = $1;
$foundSubject = 1;
} 
if($line =~ /^Date\:\s(.*)\s(\d\d\:\d\d\:\d\d)\s(.*)/) {
$date = $1;
$foundDate = 1;
$time = $2;
} 
if($line =~ /^To\:\s(\S*\@\S*)/ ) {
$to = $1;
$foundEmail = 1;
}
if($line =~ /^Size\s\=\s(\d*)/) {
$foundSize = 1;
$emailSize = $1;
}

if(($foundSubject + $foundEmail + $foundSize + $foundDate) == 4) {
print WRITELOGFILE "1,".$to.",1,,,1,".$subject.",1,".$date.",".$time.",1,,".$emailSize."\n";
$numRecords = $numRecords + 1;
$totalSize = $totalSize + $emailSize;
$emailSize = 0;
$foundSize = 0;
$foundEmail = 0;
$foundSubject= 0;
$foundDate = 0;
}

}
print "\nProcessing Complete";


Last edited by terry2009; 09-22-2009 at 07:44 AM..
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0