Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 0 down vote accepted

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


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


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

or some combination of the above.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .