Including awk (mawk) functions in a script 
Author Message
 Including awk (mawk) functions in a script

Hello All:

      Does anyone know of a way or a directive to include awk
(actually I am using mawk and may be forced to use nawk)
functions contained in seperate files?  It is starting to be a
real pain building the files by hand.

aka Winkie



Sat, 30 Aug 2003 21:27:39 GMT  
 Including awk (mawk) functions in a script


Quote:
>Hello All:

>      Does anyone know of a way or a directive to include awk
>(actually I am using mawk and may be forced to use nawk)
>functions contained in seperate files?  It is starting to be a
>real pain building the files by hand.

Use the -f option several times, e.g.:

awk -f your_script -f your_functions -f other_functions input_file

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sat, 30 Aug 2003 22:22:15 GMT  
 Including awk (mawk) functions in a script

Quote:

> Hello All:

>       Does anyone know of a way or a directive to include awk
> (actually I am using mawk and may be forced to use nawk)
> functions contained in seperate files?  It is starting to be a
> real pain building the files by hand.

> aka Winkie

Hi,

There is a sh/gawk script in the gawk distribution called
igawk which allows you to include awk functions from
other files.

If you really cant use gawk (for whatever reason) just
convert the igawk script over to sh and mawk and make
your own version (imawk).

Hope this helps,

Tristan.



Sat, 30 Aug 2003 22:25:44 GMT  
 Including awk (mawk) functions in a script

Quote:
> Hello All:

>       Does anyone know of a way or a directive to include awk
> (actually I am using mawk and may be forced to use nawk)
> functions contained in seperate files?  It is starting to be a
> real pain building the files by hand.

> aka Winkie

IIRC, you can specify many files on the command line.

I think this would work as the first line if you're using #! syntax:

#!/bin/awk -f /path/lib1.awk -f /path/lib2.awk -f

But I don't know of any way of doing it directly in *awk .

-Ed

--
Did you know that the oldest known rock is the famous |u98ejr

old?                                                  |eng.ox
                -The Hackenthorpe Book of Lies        |.ac.uk



Sat, 30 Aug 2003 22:38:10 GMT  
 Including awk (mawk) functions in a script

Quote:

> Hello All:

>       Does anyone know of a way or a directive to include awk
> (actually I am using mawk and may be forced to use nawk)
> functions contained in seperate files?  It is starting to be a
> real pain building the files by hand.

> aka Winkie

A further thought.

You could write awk scripts in a micture of AWK and (cpp|M4) and have a
shell wrapper to preprocess them and dump the contents to a temp file
and use the temp file as the source for the AWK script.

-Ed

--
Did you know that the oldest known rock is the famous |u98ejr

old?                                                  |eng.ox
                -The Hackenthorpe Book of Lies        |.ac.uk



Sun, 31 Aug 2003 04:05:00 GMT  
 Including awk (mawk) functions in a script

Quote:
> > Hello All:

> >       Does anyone know of a way or a directive to include awk
> > (actually I am using mawk and may be forced to use nawk)
> > functions contained in seperate files?  It is starting to be a
> > real pain building the files by hand.

> > aka Winkie

> IIRC, you can specify many files on the command line.

> I think this would work as the first line if you're using #! syntax:

> #!/bin/awk -f /path/lib1.awk -f /path/lib2.awk -f

> But I don't know of any way of doing it directly in *awk .

<snip>
In most (all?) shells you can't have more than one "-" parameter on the "#!"
line so multiple "-f" won't work.  Use the command line and put multiple
"-f" as suggested in Chuck Demas' reply.

Peter
--



Opinions expressed are my own and not necessarily those of my employer.



Sun, 31 Aug 2003 14:59:04 GMT  
 Including awk (mawk) functions in a script

Quote:
> > #!/bin/awk -f /path/lib1.awk -f /path/lib2.awk -f

> > But I don't know of any way of doing it directly in *awk .

> <snip>
> In most (all?) shells you can't have more than one "-" parameter on the "#!"
> line so multiple "-f" won't work.  Use the command line and put multiple
> "-f" as suggested in Chuck Demas' reply.

I thought the first argument after the #! was executed as the
interpreter and the rest was passed as command line args.

Since I don't know and this is OT, I've x-posted to comp.unix.misc and
set the followup to there.

-Ed

--
Did you know that the oldest known rock is the famous |u98ejr

old?                                                  |eng.ox
                -The Hackenthorpe Book of Lies        |.ac.uk



Mon, 01 Sep 2003 03:07:27 GMT  
 Including awk (mawk) functions in a script

Quote:


> > Hello All:

> >       Does anyone know of a way or a directive to include awk
> > (actually I am using mawk and may be forced to use nawk)
> > functions contained in seperate files?  It is starting to be a
> > real pain building the files by hand.

> > aka Winkie

> A further thought.

> You could write awk scripts in a micture of AWK and (cpp|M4) and have a
> shell wrapper to preprocess them and dump the contents to a temp file
> and use the temp file as the source for the AWK script.

> -Ed

> --
> Did you know that the oldest known rock is the famous |u98ejr

> old?                                                  |eng.ox
>                 -The Hackenthorpe Book of Lies        |.ac.uk

I've done the following (or close to it) in csh:

set files = ""
foreach f (f1 f2 f3 .... )
        set files = "$files -f $f"
end
gawk $files

The nice thing about this is that the line inside the foreach loop
can do additional stuff to the file names.
For example, if all the files are in the same directory, and
the ".awk" extension is given (using my programming slogan
"Never write anything twice."), you can write the assignment as

        set files = "$files -f ${dir}/${f}.awk"

Martin Cohen



Mon, 01 Sep 2003 12:55:57 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. include library in awk-script

2. How to include the tk.h functions in TCL script

3. help for new user looking to use awk nawk or mawk

4. Differences between awk/nawk/gawk/mawk

5. gawk/mawk/awk Conflict re OFMT?

6. awk on DigitalUNIX, mawk, tawk

7. Mawk, a version of new awk

8. Creating an awk script to extract other scripts from a file

9. Access to Script Name Within Awk Script

10. Problem of include file in AWK [HP-UH10.20]

11. found french book about scripting languages including Ruby

12. include vrml in HTML as a script?

 

 
Powered by phpBB® Forum Software