Say with the below awk inside a bash script:
How can you get the print_line function to print the name of the argument passed in?
ie this output
array passed in was:
arrayprime
array passed in was:
arraymagic
Just a snippet of the gist of the code (not whole thing):
awk -F"$delim" '
NR>1 {
print_line(arrayprime)
print_line(arraymagic)
}
func print_line(arr)
{
print "array passed in was:"
print arr
}
} ' "$filename"
No,
awkdoes not have the ability to be this introspective.The
Clanguage can do this through the use of the C preprocessor. If you really want to roll this type of behavior into your awk function, then you could look into use the C preprocessor or perhaps write a GNU M4 macroIf you’re willing to add just one more parameter, you could do.