8

I am using Ubuntu 14.04, and making heavy use of all the great commands awk, sed, sort and so on.

Recently it came to my attention that Ubuntu uses mawk as the default implementation, but since I wanted to use some functionality specific to gawk, I promptly apt-get installed that package.

At that point, it seems that my Ubuntu switched to gawk as the default, which I did not want, since it has some subtle differences in behavior (for example, rand() seems to be deterministic in gawk, which is very bad since I use it all the time).

How can I have both packages installed, but use mawk as the default implementation?

1 Answer 1

14

You can set the default via the update-alternatives mechanism, using the command

sudo update-alternatives --config awk

e.g.

$ sudo update-alternatives --config awk
There are 2 choices for the alternative awk (providing /usr/bin/awk).

  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gawk    10        auto mode
  1            /usr/bin/gawk    10        manual mode
  2            /usr/bin/mawk    5         manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/mawk to provide /usr/bin/awk (awk) in manual mode.

When you want gawk instead, simply invoke it as gawk instead of awk

1
  • 2
    Thanks for pointing me to update-alternatives, I had no idea that this functionality existed.
    – mitchus
    Commented Dec 15, 2014 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .