The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
select a portion of a file into a CSV anju Shell Programming and Scripting 8 02-27-2008 10:50 PM
Delete Portion of a file sameersbn High Level Programming 2 01-19-2007 09:16 PM
extract a portion of log file chandra004 Shell Programming and Scripting 8 08-03-2006 05:20 PM
display a portion of lines from file champion UNIX for Dummies Questions & Answers 6 09-20-2005 08:11 AM
remove portion of file methos Shell Programming and Scripting 13 08-16-2002 06:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-02-2005
srikanth_ksv's Avatar
Registered User
 

Join Date: May 2005
Location: Chennai
Posts: 14
Separate a portion of text file into another file

Hi,

I have my input as follows :

I have given two entries-

From system Mon Aug 1 23:52:47 2005
Source !100000006!:
Impact !100000005!: High
Status ! 7!: New
Last Name+!100000001!:
First Name+ !100000003!:
Phone !100000004!:
email !100000000!: xyz@abc.com
Problem Detail !100000000!: Automated Ticket Script Problem
Script was unable to complete due to

From system Mon Aug 2 08:56:47 2005
Source !100000006!:
Impact !100000005!: High
Status ! 7!: New
Last Name+!100000001!:
First Name+ !100000003!:
Phone !100000004!:
email !100000000!: pqr@abc.com
Problem Detail !100000000!: Automated Ticket Script Problem
Script was unable to complete due to


The above is like a template and it would repeating in my input file and the would be also be updated with new entries from time to time.

What I want to do is for each entry I want to extract the email id and mail the content to that email id.

So what I thought is that if I could get each entry into a temporary file, then I could extract the email id from that and use mailx to send the mail.
But how should I go about separating the entries is the big problem.
Please Help.
Any other approaches to the problem are also welcome.

Thanks in advance,
srikanth
Reply With Quote
Forum Sponsor
  #2  
Old 08-02-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
something along these lines - not tested.

nawk -f sri.awk myInputFile

sri.awk:
Code:
BEGIN {
  FS=RS=""
}
{
  for(i=1; i <= NF; i++)
    if( match($i, "^email.*!:") ) {
       addr=substr($i, RSTART+RLENGTH+1)
       break;
    }
    printf("addr->[%s]\n", addr)
    cmd= "mailx " addr
    print | cmd
    close(cmd)
}
Reply With Quote
  #3  
Old 08-03-2005
srikanth_ksv's Avatar
Registered User
 

Join Date: May 2005
Location: Chennai
Posts: 14
Thanks Vgersh,

But it did not work. This was the output which I got when I ran it with my input.


addr->[]
No mail for fe598
addr->[]
No mail for fe598
addr->[]
No mail for fe598
addr->[]
No mail for fe598
addr->[]
No mail for fe598
addr->[]
No mail for fe598


Regards,
srikanth.
Reply With Quote
  #4  
Old 08-03-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
here's the output I get based on the sample input file you've provided:
Code:
nawk -f sri.awk sample.txt 
addr->[xyz@abc.com]
addr->[pqr@abc.com]
Validate your real file jives with what you've posted originally.
Reply With Quote
  #5  
Old 08-05-2005
srikanth_ksv's Avatar
Registered User
 

Join Date: May 2005
Location: Chennai
Posts: 14
Thanks

Thanks a lot Vgersh99 for your inputs
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0