Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've just started learning awk and I'm a little confused about all those versions around. Is there any "version" which is found on all Unix-like systems? Like, you know, plain vi? Does the standard awk support the -F option?

share|improve this question

migrated from stackoverflow.com Nov 27 '09 at 9:57

This question came from our site for professional and enthusiast programmers.

add comment

5 Answers 5

awk - the most common and will be found on most Unix-like systems, oldest version and inferior to newer ones.

mawk - fast AWK implementation which it's code base is based on a byte-code interpreter.

nawk - while the AWK language was being developed the authors released a new version (hence the n - new awk) to avoid confusion. Think of it like the Python 3.0 of AWK.

gawk - abbreviated from GNU awk. The only version in which the developers attempted to add i18n support. Allowed users to write their own C shared libraries to extend it with their own "plug-ins". This version is the standard implementation for Linux, original AWK was written for Unix v7.

There are other versions like jawk (java implementation), bwk (Brian W. Kernighan's implementation) and so on.

share|improve this answer
2  
The original awk isn't present on any Unix-like system I have available. Often, /usr/bin/awk will run nawk, or gawk, or BusyBox awk (similar in behavior to gawk). –  dubiousjim Apr 19 '12 at 10:46
2  
As of late 2012, Ubuntu/Debian systems install mawk by default. The command line file /etc/alternatives/awk returns symbolic link to /usr/bin/mawk –  Mike Sherrill 'Cat Recall' Dec 5 '12 at 22:28
    
does MAWK have all GAWK functionalities such as true multi-dimensional arrays ? –  bharat_iyengar Jul 9 '13 at 5:35
add comment

You can just use awk. It is defined by POSIX and therefore has to exist on all POSIX-conformant systems.

The -F parameter is mandated by that as well.

share|improve this answer
    
...but take care to check with the standard to tell what you can use to insure compatibility with other version. Don't, for instance, use gensub(), test with awk --> gawk, and think you're good to go... –  dmckee Nov 28 '09 at 2:47
add comment

awk will be on just about every *NIX based system, but the exact specifics of what it supports will shift slightly as it's entirely possible it will simply be symlinked to a different version akin to how /bin/sh is often linked to a specific shell, often bash or one of its derivatives. (For the record, I also know alot of machines where vi is symlinked to vim as well.)

share|improve this answer
    
Needn't always be symlinked; sometimes it's hard-linked. –  dubiousjim Apr 19 '12 at 10:47
add comment

The Wikipedia AWK page is a good starter reference for beginning to understand AWK.
The Field Separator option '-F' is supported in all variants of AWK -- afaik.

share|improve this answer
add comment

First the quick answer:

You don't have to bother: Your system's awk is just a symlink to either mawk or gawk AND more importantly: all three versions, awk, mawk and gawk are completely compatible. There is (said to be) a difference in speed between awk/gawk and mawk being the (said to be) faster.

The only exception is nawk which lacks some functionality, but chances to find this one in the wild are rather scarce.

share|improve this answer
add comment

Your Answer

 
discard

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