bash-3.00# awk '{print NR}' f1.txt

but FNR does not print anything.

awk '{print FNR}' f1.txt

the above line does not gives me any output,seems that the awk that i am having in my sun os does not have FNR variable. so can i do something about it to standardize it. also, can i get a library of all latest commands and install/update my current commands like sed,sort etc.

SunOS unknown 5.10 Generic_142910-17 i86pc i386 i86pc

  • On Solaris, don't ever try using awk. It's terrible. Always use nawk, which is also installed by default. – steve Aug 18 '15 at 15:45

There is not just one awk and several releases of it. There are many awk implementations which each have several versions. All Unices have their own toolset which they maintain in-house and the software that ships with one Unix and that make use of those tools generally rely on those being the exact version of that very implementation.

If you start replacing /usr/bin/awk with the GNU awk as can be downloaded from http://gnu.org, then you'll run into problems.

Some Unices do package alternative or Free Software versions of some of the standard utilities. Generally, they do that by installing them in a different location (/opt/gnu for instance for GNU tools) or under a different name (gawk for GNU awk). If not you can download them as source and build them and install them in a different location or under a different name manually yourself.

Having said that, Solaris is known to have very old and non-standard versions of some utilities in /usr/bin and keep the modern/standard versions in another place.

That's the case of awk. /usr/bin/awk on Solaris is based on the original awk from 1979. awk was rewritten circa 1988 and called nawk. All modern awk implementations are based on that nawk (as that's what the POSIX awk specification is based on).

On Solaris, if you update your $PATH to put yourself in a standard/POSIX environment (which generally involves putting /usr/xpg4/bin and/or /usr/xpg6/bin at the start of $PATH), then awk will be the standard one. Alternatively, you can call nawk instead of awk.

That's the same for sh, you can use /usr/xpg4/bin/sh or ksh.

In a standard sh (that is, not /bin/sh on Solaris), you can also use

 command -p awk

To be sure to call the portable awk instead of the old one.

  • Or you can use PATH=$(getconf PATH) awk to get the new awk compliant with POSIX instead of the old one. – cuonglm Aug 18 '15 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.