55

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?

Oliver Salzburg
  • 86,445
  • 63
  • 260
  • 306
  • 1
    See also [The differences between gawk and mawk (column width)](https://stackoverflow.com/questions/21289110/the-differences-between-gawk-and-mawk-column-width) – Joshua Goldberg Nov 19 '20 at 18:15

4 Answers4

51

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.

John T
  • 163,373
  • 27
  • 341
  • 348
  • 5
    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
  • 15
    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 05 '12 at 22:28
  • does MAWK have all GAWK functionalities such as true multi-dimensional arrays ? – WYSIWYG Jul 09 '13 at 05:35
  • I know this is late @WYSIWYG but mawk does have a few quirks, mainly with regexp's though you are best to install gawk if you want a portable implementation IMO. – Jordon Bedwell Aug 11 '15 at 09:50
  • 3
    @JordonBedwell Yep.. There are: regex repetitions are not possible in mawk. It also doesn't support multidimensional arrays. – WYSIWYG Aug 11 '15 at 10:25
  • 1
    @dubiousjim Ubuntu has original-awk in the universe repository. – jarno Sep 01 '15 at 09:19
  • @WYSIWYG Also some functions like `strtonum` are missing. – phk Jan 01 '17 at 21:01
  • My Raspbian Stretch installation has `awk`, `gawk`, `igawk`, `mawk` and `nawk`. available, but `awk`, `nawk` and `igawk` are either symlinks to, or wrappers of, `gawk`. Interestingly, on the more up-to-date Raspbian Buster I installed a few days ago, `(i)gawk` has vanished and all the symlinks now point to `mawk`. Quirky it may, be but it seems `mawk` is the future, at least on certain distros. – Bob Sammers Mar 06 '20 at 10:26
7

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.

Joey
  • 40,002
  • 15
  • 104
  • 126
  • 2
    ...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 --- ex-moderator kitten Nov 28 '09 at 02:47
  • 2
    @dmckee, you can use `gawk --posix` to make gawk work according to POSIX standard. It also checks your script follows the standard. You could use `awk --posix '' 2>/dev/null` in Ubuntu no matter, if gawk, mawk or original-awk is used as awk, but the posix-option is only recognized by gawk. --posix has to be the last option for original-awk. You could use `awk -W posix ''` with gawk and mawk. – jarno Sep 01 '15 at 09:34
  • 1
    @dmckee, oh `mawk --posix ''` fails, if you use mawk 1.3.3, but succeeds with error message, if you use mawk 1.3.4 – jarno Sep 02 '15 at 09:46
2

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.)

Matthew Scharley
  • 4,463
  • 3
  • 26
  • 21
1

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.

nik
  • 55,788
  • 10
  • 98
  • 140