[comp.unix] AWK and the system

tigger@homxc.UUCP (K.VENNER) (06/05/87)

To all you netlanders:

Here I sit, trying to write some utilities to handle distribution
lists, labels and electronic mail.  What I am really trying
to do is replace a single line within a file with the output
of either a shell script or the output of a whole different file.

I am attempting to do something identical to the idea of
the  "#include (filename)" statement within a "C" program.

The awk program would look like:

    awk ' $1 == "The proper line" {system("cat file1") }' 

Looking at the technical document on AWK (doc # 11272-850619-06TM)
page 24 is an example of what I am trying to accomplish.

Any suggestions, I am totally baffled, and right now the Unix
counseling at my site is too busy to get too much headway on 
this problem.
-- 
------------------------------------------------------------------------------
                               ____   _______   _____   _______     ------- 
Ken Venner                    / __ \ |__   __| /   _ \ |__   __|  -====------
AT&T Bell Laboratories       | (__) |   | |    \  \ \_\   | |    -======------
HO 1D-425A   x9080           |  __  |   | |    /   \ __   | |    --====-------
Holmdel, NJ                  | |  | |   | |   |  (\ / /   | |     -----------
...!ihnp4!homxc!tigger       |_|  |_|   |_|    \_____/    |_|       -------


Disclaimer:  My opinions are soley my own!

usenet@mcdchg.UUCP (The Moderator) (06/18/87)

[Here are two responses on the AWK question.  -mod]

--------
From: domo@sphinx.co.uk

"There is no problem that cannot be solved by adding one level of
indirection."  Somebody like Dijkstra said something like that.

			-- Anyway --

What you can do is have awk generate a shell script containing the cat
commands:

	awk ' S1 == "The proper line" {print "cat file1"}' | sh

Have fun.
Dominic Dunlop   Sphinx Ltd.  (domo@sphinx.co.uk)

-----

From: Brian Katzung <katzung@laidbak.UUCP>
Organization: Lachman Associates, Inc, Chicago

awk '
	{
		if ($1 == "#include")
			system("cat " $2)
		else
			print
	}'

I don't have a SVR3 system handy just now, but I believe you will
find that this awk program copies its input to its output, replacing
lines of the form

	#include some_file

with the contents of some_file.
-- Brian Katzung  ihnp4!laidbak!katzung