Novice having merge problem 
Author Message
 Novice having merge problem


%    "sed -f tmp.sed tmp.master > letter" | getline
%    "lp letter" | getline

% My problem is that only one letter is ever printed (the first SREC in the
% database file) even though I can see by the print statements that the
% database file is being run through over and over again for all of the
% records.  If I comment the line to remove the tmp.sed file, it contains the
% last record from the database file.

The problem is with the two lines I quote above. awk opens a pipeline
from the programs sed and lp, and it leaves it open until you explicitly
close it. So, the second time around, it doesn't bother running sed or lp --
it just tries to read a line of output from the previously running ones.

In this case, what you want to do is use the system function to run
these programs:
 system("sed -f tmp.sed tmp.master | lp")
[editorial note: what you really want to do is process tmp.master with awk :]

In a case where you really wanted to pipe output into getline, you
would need to call close() to shut the program down:
 close("sed -f tmp.sed tmp.master > letter")
 close("lp letter")

The command and its arguments must exactly match the command used in the

Patrick TJ McPhee
East York  Canada

Tue, 19 Dec 2000 03:00:00 GMT  
 Novice having merge problem

>Hello Everyone;

>I am just beginning to learn how to use the awk programming language.  I am
>trying to pull lines of text from a database (text) file into a form letter


for a completely different way to construct a form letter from a template
and a data file, try the following, which I hope simplifies your work.

Clyde Ingram


>% Is there a way to have thoses fields added to form letter and mail out
>% using mail on a UNIX box. I can send the output file but I want to parse
>% that file using the name and filesize into individual mails.

>It's not clear to me what you're trying to do.
>Patrick TJ McPhee

It is not clear to me either.  But if Huge wants to generate and mail a form
letter, plugging in a different set of values from a data file, there is a
smart little Form Letters program in "The AWK Programming Language", by Aho,
Weinberger, and Kernighan.  (This is the book that knocks the spots right
off the O'Reilly "sed & awk" book.)

Given a file 'letter.txt', containing something like:

Dear #1,

Subject: #2
Blah blah blah
See you, #1, on #3

and a file 'data.txt', containing:

Fred:Todays Events:Friday
Bill:Sale Items:Monday
Harry:AWK Programming:Saturday

a command like 'awk -f formgen.awk data.txt' generates letters like

Dear Fred,

Subject: Todays Events
Blah blah blah
See you, Fred, on Friday

And the AWK script, 'formgen.awk' doing this is (to almost quote the good

    FS = ":"
    while (getline <"letter.txt" > 0)    # read form letter
        form[++n] = $0


{   for (i = 1; i<= n; i++)        # read data lines
        temp = form[i]            # each line generates a letter

        for (j = 1; j <= NF; j++)
            gsub("#"  j, $j, temp)

        print temp


Hope this helps.
Clyde Ingram

Fri, 22 Dec 2000 03:00:00 GMT  
 [ 3 post ] 

 Relevant Pages 

1. Novice Programmer needs help doing something simple, MERGE

2. Having problems changing printer settings within the program code (anyone having problems w/ OkiData printers?)

3. Merging To Word Perfect Problem

4. Sort and Merge problem

5. file merge problem

6. Merge problem with latest CVS

7. novice has gsub() problem (NAWK) ... is perl easier

8. Novice's Eiffel problem

9. FSM problem faced by novice..

10. Novice PHP User: Very basic problem with IIS

11. Novice w/ Compile Problems ... Python 2.1.3

12. Pear on Windows 98 - Novice problems


Powered by phpBB® Forum Software