awk + fit syntax for SUN solaris & linux

1

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

lidia

Posted 2010-09-02T08:15:03.657

Reputation: 629

Answers

0

Try nawk or /usr/xpg4/bin/awk or /usr/xpg6/bin/awk instead of awk

or

awk 'BEGIN {NAME=MACHINE} $1 == NAME'  /etc/hosts

or

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

or some combination of the above.

Paused until further notice.

Posted 2010-09-02T08:15:03.657

Reputation: 86 075