我发现AWK的所有功能都包含在GAWK中,除了使用没有安装GAWK的系统外,我是否应该使用AWK与GAWK?AWK的性能是否优于GAWK?
awk可以参考很多东西.这是awk标准,有许多不同的实现,其中之一是gawk.
不使用特定于实现的功能意味着您将有很高的机会让您的代码在其他awk语言实现上保持不变.
gawk作为一种awk语言的实现,声称符合awk标准,同时添加一些额外的功能.
$ man awk
…
DESCRIPTION
Gawk is the GNU Project's implementation of the AWK programming
language. It conforms to the definition of the language in the
POSIX 1003.1 Standard. This version in turn is based on the
description in The AWK Programming Language, by Aho, Kernighan,
and Weinberger. Gawk provides the additional features found in
the current version of Brian Kernighan's awk and a number of
GNU-specific extensions.
…
Run Code Online (Sandbox Code Playgroud)
至于速度,使用gawk"普通" awk应该没有区别 - 通常,gawk安装时,awk只是一个符号链接,gawk这意味着它们将是完全相同的程序.
但是,使用gawk特定功能意味着您将被锁定在该特定实现中 - 因此,如果(假设)您发现更快的实现,您可能必须调整脚本而不是仅仅交换二进制文件.(可能有更快的实现,但我不知道,因为我从来没有需要让我的awk脚本运行得更快.)
就个人而言,我倾向于坚持"普通" awk而不是使用gawk特定功能,但如果您不关心切换到其他实现,使用gawk扩展可能会使您的脚本更容易编写并节省您的时间.