As has been stated in hundreds of threads before, when running awk scripts on Solaris/SunOS systems, change awk to /usr/xpg4/bin/awk or nawk . (And, if there are any internationalized EREs, don't use nawk either. But, that isn't a problem in this script.)
But, your code is also depending on something else that is unspecified in the standards: the standards don't specify the precedence of file redirection versus string concatenation. So, to make your script more portable, use: