Send mail based on a group | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Send mail based on a group

Shell Programming and Scripting


Tags
awk, file, mail, sed

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-10-2012
Max499 Max499 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 24 January 2013, 4:38 PM EST
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Tools Send mail based on a group

Hello Gurus,
I have a question.

I have a file which has 2 columns and is tab separated and looks like below:

FIELD1 FIELD2

Code:
Manual m456@hotmail.com
Execution din098@gmail.com 
Artistic m456@hotmail.com
Graphic din098@gmail.com

FIELD2 values will have always either of the 2 above mentioned email addresses.What i'm trying to do is sort the FIELD2 values according to the email addresses i.e. which would look like below.

FIELD1 FIELD2

Code:
Manual m456@hotmail.com
Artistic m456@hotmail.com
Execution din098@gmail.com
Graphic din098@gmail.com

Now i would like to send only 1 email to the email address 'm456@hotmail.com' saying that you have two values assigned to you namely (Manual and artistic) and i would even want to send only 1 email to 'din098@gmail.com' saying that you have two values assigned to you namely (Execution and Graphic).

Could anybody please help me achieve the above requirement ?
Any help is highly appreciated.

Last edited by Franklin52; 12-11-2012 at 04:21 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old 12-10-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 October 2014, 4:20 PM EDT
Location: Galactic Empire
Posts: 3,387
Thanks: 235
Thanked 1,209 Times in 1,135 Posts

Code:
awk 'NR>1 { print $2 | "sort | uniq" } ' input_file | while read mail_id
do
        awk ' BEGIN { print "Assigned Values: " } /'$mail_id'/ { print $1 } ' input_file | mailx -s "Group Info" ${mail_id}
done

The Following User Says Thank You to Yoda For This Useful Post:
Max499 (12-12-2012)
Sponsored Links
    #3  
Old 12-10-2012
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 
Join Date: Jun 2006
Last Activity: 22 March 2014, 12:27 PM EDT
Posts: 2,759
Thanks: 44
Thanked 418 Times in 406 Posts

Code:
awk '{a[$NF]=a[$NF] FS $1}END{for (i in a) print "Assigned Values: " ,a[i] |mailx -s "Group info" i}' infile

The Following User Says Thank You to rdcwayx For This Useful Post:
Max499 (12-12-2012)
    #4  
Old 12-11-2012
Max499 Max499 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 24 January 2013, 4:38 PM EST
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Thank you very much gurus bipinajith and rdcwayx, i really appreciate your quick help.
Sponsored Links
    #5  
Old 12-12-2012
Max499 Max499 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 24 January 2013, 4:38 PM EST
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks very much.

Last edited by Max499; 01-24-2013 at 03:34 PM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #6  
Old 01-24-2013
Max499 Max499 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 24 January 2013, 4:38 PM EST
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Missing First row-- Please help

Hi bipinajith,

Actually the code would miss the first line and it's reading from the second line.
For instance if i have only one row of data, then there's no email sent to anybody.
I've tried removing NR>1 but it still does the same.
Can somebody help me with it please.
Sponsored Links
    #7  
Old 01-24-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 October 2014, 4:20 PM EDT
Location: Galactic Empire
Posts: 3,387
Thanks: 235
Thanked 1,209 Times in 1,135 Posts
I put NR>1 to avoid the file header FIELD1 FIELD2

So removing NR>1 should work:

Code:
awk '{ print $2 | "sort | uniq" } ' input_file

Can you explain what exactly is the issue that you are facing?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need to configure mail setting to send mail to outlook mail server amitranjansahu UNIX for Advanced & Expert Users 2 02-18-2011 06:29 AM
how to write a shellscript to send a mail alert to the website user based on license expiration time deepu_Shscripts Shell Programming and Scripting 0 09-03-2010 02:55 AM
How to send html file in a mail not as an attachment but it should display in the mail in table for mani_isha UNIX for Dummies Questions & Answers 0 03-30-2010 03:37 AM
send attachments using send mail in Solaris mohan_kumarcs UNIX for Advanced & Expert Users 1 04-25-2009 12:36 PM
can not send mail from unix server to company/yahoo mail b5fnpct UNIX for Dummies Questions & Answers 5 11-22-2002 08:24 PM



All times are GMT -4. The time now is 06:24 PM.