Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is including the header in the sort.

awk -f average1.awk $1 | sort

In the shell you can do

awk -f average1.awk "$1" | (read h; echo "$h"; sort)

Within the awk script you can do something like

NR==1 {print}
... {print | "sort"}
1 Like