[Cialug] MailMerge

Crouse crouse at usalug.net
Mon Apr 21 22:51:50 CDT 2014


Bash isn't that hard, and definitely not as ugly as perl ;)

 datafile.txt
---------------------
Joe Smith:1001 E. 101st Street:Des Moines:IA:50310:jsmith at someisp.net
Mary Smith:120 NW 1st Street:Fort Wayne:IN:44334:msmith at someotherisp.net


bash script
--------------------
#!/bin/bash
for line in `cat datafile.txt`; do
    NAME=`echo $line | awk -F : '{ print $1 }'`
    ADDR=`echo $line | awk -F : '{ print $2 }'`
    CITY=`echo $line | awk -F : '{ print $3 }'`
    STATE=`echo $line | awk -F : '{ print $4 }'`
    ZIP=`echo $line | awk -F : '{ print $5 }'`
    EMAIL=`echo $line | awk -F : '{ print $6 }'`

    cat Message.txt | sed
"s/NAME/$NAME/g;s/ADDR/$ADDR/g;s/CITY/$CITY/g;s/STATE/$STATE/g;s/ZIP/$ZIP/g;s/EMAIL/$EMAIL/g;"
| mail -s 'YOUR SUBJECT HERE' $EMAIL

done;


On Mon, Apr 21, 2014 at 9:43 PM, Scott Yates <Scott at yatesframe.com> wrote:

> Hey now.  Whats with all the Perl hate!
>
>
> On Mon, Apr 21, 2014 at 9:11 PM, jim kraai <jimgkraai at gmail.com> wrote:
>
> > Awk, old school
> > Python, my favorite
> > Bash/etc., ugly
> > Anything procedural that can iterate over an input file
> >
> > Perl if you hate yourself ;-)
> > Powershell if you _really_ hate yourself
> >  On Apr 21, 2014 9:01 PM, "L. V. Lammert" <lvl at omnitec.net> wrote:
> >
> > > Definitely not Word or Write, ... but a simple way to take a template
> > file
> > > and a list of data/emails and produce individual emails.
> > >
> > > Primary need is to include specific data in the email body, as when
> using
> > > BCCs the recipient is obscured.
> > >
> > > I see a mailmerge in Perl, but looking to see if that's the best
> option.
> > >
> > >         Thanks!
> > >
> > >         Lee
> > > _______________________________________________
> > > Cialug mailing list
> > > Cialug at cialug.org
> > > http://cialug.org/mailman/listinfo/cialug
> > >
> > _______________________________________________
> > Cialug mailing list
> > Cialug at cialug.org
> > http://cialug.org/mailman/listinfo/cialug
> >
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>


More information about the Cialug mailing list