You can have several parameters -f program-file, so you can be your common functions, and the other may be a problem solving awk script that will have access to these functions.
awk -f common-funcs.awk -f specific.awk file-to-process.txt
I don’t know, this is what you were looking for, but this is the best I came up with. Here is an example:
$ cat common_func.awk
function trim(s) {
gsub(/^[ \t]+/, "", s);
gsub(/[ \t]+$/, "", s);
return s;
}
$ cat specific.awk
{ print $1, $2 }
{ print trim($1), trim($2) }
$ cat file-to-process.txt
abc | def |
2$ awk -F\| -f common_func.awk -f specific.awk file-to-process.txt
abc def
abc def
With regular awk (non-gnu), you cannot mix an option -f program-filewith a firmware. That is, the following will not work:
awk -f common_func.awk '{ print trim($1) }' file-to-process.txt
, , gawk -f -e:
awk -f file.awk -e '{stuff}' file.txt