![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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)
}
|
|
#3
|
||||
|
||||
|
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. |
|
#4
|
||||
|
||||
|
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] |
|
#5
|
||||
|
||||
|
Thanks
Thanks a lot Vgersh99 for your inputs
|
||||
| Google The UNIX and Linux Forums |