Here’s what I’m currently trying as a base case with the function definition written manually (which works):
igawk 'function tripleit(x) {return x*3} {print tripleit($1)}' <(echo 5)
Here is a theoretically more practical version calling a function library (which fails):
igawk '@include $HOME/code/thefunc {print tripleit($1)}' <(echo 5)
Here's "thefunc" :
function tripleit(x){return x*3}
If anyone knows HOW or WHY this is failing, and how I can get something like this to work, it would be super-helpful. I love AWK, but I'm not about to type and retype UDFs each and every time I need them.
I have tried to create foo.awk: function foo(){print "Hello World"}
And call this as suggested:
$ cat foo.awk
function foo(){print "Hello World"}
$ igawk '@include "foo.awk"; BEGIN{foo()}'
igawk:/dev/stdin:0: cannot find "foo.awk";
$ igawk '@include "$PWD/foo.awk"; BEGIN{foo()}'
$ igawk '@include "./foo.awk"; BEGIN{foo()}'
$
No output yet.
awk has no idea what the shell variable
$HOMEcontains and@includerequires a string as it's argument.You can also use AWKPATH instead of explitly providing the library directory path every time:
alternatively try: