awk + fit syntax for SUN solaris & linux

爷,独闯天下 提交于 2019-12-02 07:09:30

问题


need help about the following

when I run the following command on linux its run fine

  awk -v NAME=MACHINE '$1 == NAME'  /etc/hosts 

but on SUN Solaris I get the following:

 awk -v NAME=MACHINE '$1 == NAME'  /etc/hosts 
 awk: syntax error near line 1
 awk: bailing out near line 1

how to fit the following syntax in order to fit also SUN Solaris? or change in order to fit both on linux and SUN Solaris


回答1:


Solaris is well known for the fact that the some commands under /bin /usr/bin are not POSIX compliant. Instead they have additional compliant versions under /usr/xpg4 and similar hierarchies.

Thus, under Solaris you can use just:

/usr/xpg4/bin/awk -v NAME=MACHINE '$1 == NAME'  /etc/hosts 

Under Solaris 10 this works.




回答2:


the simple way is to use nawk and the rest syntax



来源:https://stackoverflow.com/questions/3624748/awk-fit-syntax-for-sun-solaris-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!