Question
Write a linux bash script named Merge to do a mail merge, i.e., fill in values into a form letter. You may invoke awk and/or
Write a linux bash script named Merge to do a mail merge, i.e., fill in values into a form letter. You may invoke awk and/or sed in your bash script, as needed. For example, you might have your bash script dynamically construct a sed program and execute it.
The first argument to the script should be a text file that is the template for the form letter, called the template file. Inside this file, text of the form %n for integer n indicates that this will be replaced by field number n during the merge. The second argument to the script should be a text file with fields, called the database file. Fields are separated by commas and records are separated by newline characters.
The script should produce text files in the current directory, named 1.txt, 2.txt, . . . , m.txt where m is the number of lines in the database file. File i.txt should be the template file, with fields plugged in according to record i (line number i) in the database file. If record i has fewer fields than what is required by the template, then the missing values should remain un-replaced.
For example:
user$ cat ../templ.txt
Dear %1,
Thank you for your generous donation of %2 to the re-election campaign of your politician. Rest assured: politician is very committed to %3 and will not rest until this is achieved.
Remember to vote on November 6!
user$ cat ../data.txt
Curly,$50,rebuilding infrastructure
Moe,$15,destroying infrastructure
Larry,$2,raising taxes
Shemp,10 cents,lowering taxes
Joe,string
user$ Merge ../templ.txt ../data.txt
user$ ls
1.txt 2.txt 3.txt 4.txt 5.txt
user$ cat 4.txt
Dear Shemp,
Thank you for your generous donation of 10 cents to the re-election campaign of your politician. Rest assured: politician is very committed to lowering taxes and will not rest until this is achieved.
Remember to vote on November 6!
user$ cat 5.txt
Dear Joe, Thank you for your generous donation of string to the re-election campaign of your politician. Rest assured: politician is very committed to %3 and will not rest until this is achieved.
Remember to vote on November 6!
user$
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started