Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
 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

share|improve this question

1 Answer 1

up vote 7 down vote accepted

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 alternate or Free Software versions 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 1981. awk was rewritten circa 1988 and called nawk. All modern awk implementations are based on that nawk.

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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