put awk script into a function and use feature detection for egrep -o option