我有2个主机:一个正在运行Linux
,而另一个正在运行OmniOS
。
awk
上的Linux
为gawk
:
[root@localhost ~]# which awk
/bin/awk
[root@localhost ~]# ls -lt /bin/awk
lrwxrwxrwx. 1 root root 4 Jan 22 2014 /bin/awk -> gawk
运行以下命令即可:
[root@localhost ~]# awk 'function print_name_and_age(name, age) { print name" is "age" old" } {print_name_and_age($1, $2)}'
Mark 12
Mark is 12 old
我认为awk
上的OmniOS
是nawk
,但不确定:
root@localhost:/root# which awk
/usr/bin/awk
root@localhost:/root# ls -lt /usr/bin/awk
-r-xr-xr-x 2 root bin 90664 Apr 3 01:17 /usr/bin/awk
root@localhost:/root# awk
awk: Usage: awk [-Fc] [-f source | 'cmds'] [files]
但执行相同的命令是错误:
root@localhost:/root# awk 'function print_name_and_age(name, age) { print name" is "age" old" } {print_name_and_age($1, $2)}'
awk: syntax error near line 1
awk: bailing out near line 1
我无法找出根本原因,任何人都可以提供任何线索吗?