Combining awk Inline and File Code

I've ended up with a small collection of libraries I like to use with awk, but this means I can't do awk -f librarycode.awk '{ program code }' filename because awk will assume that anything after -f is a filename, not code. Is there any way I can do both?

Multiple -f's ?
Or if you're using 'gawk', use 'igawk' with the '@include' pragma.

1 Like

Multiple -f's work but clutter up my directories with lots of tiny one-liner files.

@include is better, thank you.

you can have a separate directory with all your library files, and specify absolute/relative paths for libs and a -f for your 'core' script. [not sure I'm addressing your concern tho ;)]

Whether this is what you are looking for ?

akshay@Aix:/tmp$ cat a.awk 
function test(text){
print text
}

akshay@Aix:/tmp$ awk -f a.awk  --source 'BEGIN{test("Test me")}'
Test me
1 Like

That's exactly what I was looking for. Is that really AIX? If it works in awks that aren't GNU awk that's terrific.

No its ubuntu I like "Aix", its just hostname, infact all my servers lap has same name