简体   繁体   English

如何在macOS上获取AWK版本?

[英]How to get awk version on macOS?

I know how to get the version for awk on Linux: awk -W version 我知道如何在Linux上获取awk的版本: awk -W version

This doesn't work, however, on macOS. 但是,这在macOS上不起作用。

I looked around on SO and couldn't find anything. 我四处张望,找不到任何东西。

I also looked in the awk man page and couldn't find anything: 我还查看了awk手册页,但找不到任何内容:

$ man awk | grep version
          conversion format used when converting numbers (default %.6g)
   There are no explicit conversions  between  numbers  and  strings.   To
awk --version
awk version 20070501

The EASY way when -v , -V , -version or --version are available (this option is available in most of cases): -v-V-version--version可用时的简便方法(此选项在大多数情况下可用):

awk --version
awk version 20070501

or 要么

awk -version
awk version 20070501

Now when it is not available, we go the hard way: 现在,当它不可用时,我们会努力进行

whereis awk
/usr/bin/awk

then 然后

what /usr/bin/awk 
/usr/bin/awk
    PROGRAM:awk  PROJECT:awk-24

and

strings /usr/bin/awk | grep -Ei "version|awk" 
/BuildRoot/Library/Caches/com.apple.xbs/Sources/awk/awk-24/src/b.c
version 20070501
bin/awk
-version
--version
awk %s
awkdelete
weird printf conversion %s
can't happen: bad conversion %c in format()
out of memory in awksprintf
out of memory in awkprintf
@(#)PROGRAM:awk  PROJECT:awk-24

You find most all the information you were looking for by reading the strings in the binary and by using grep to isolate what you are really looking for. 您可以通过读取二进制文件中的字符串并使用grep隔离真正要查找的内容来找到所需的大多数信息。 (Side note you have also find out that -version and --version are arguments that can be used) (附带说明,您还发现-version--version是可以使用的参数)

You can also use grep -Eai "\\bversion\\b|awk|unix" /usr/bin/awk to reach the same result (little less readable) 您还可以使用grep -Eai "\\bversion\\b|awk|unix" /usr/bin/awk达到相同的结果(可读性较差)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM