awk syntax for Solaris

Hi,

Pass variable in SUN SOLARIS awk

I have a file call text

server1 10.0.0.2

When i use this awk command in Mac OS and Linux , everything works as expected.

export HOSTNAME=server1
awk -v HOSTNAME=$HOSTNAME ' $1 ~ HOSTNAME { print $2 ; } ' text1

But when i entered the same command on Solaris it came back with syntax error.

Thanks

Hi.

On Solaris use nawk, or /usr/xpg4/bin/awk.

I would personally delete /usr/bin/awk and link it to nawk!! (but maybe that's just me!)

for the OLD awk on Solaris pass the vars the follwing way:

awk ' $1 ~ HOSTNAME { print $2 } ' HOSTNAME="${HOSTNAME}" text1

Yes, it would have been constructive to say "the OLD awk on Solaris" doesn't support the -v option!

But it's about the only awk that doesn't.

Thank you all.

I am trying to run awk in finish script after jumpstart installation on Solaris 10 X86.
The boot image during jumpstart does not have awk in /usr/xpg4.

And it doesn't work if I use
awk ' $1 ~ HOSTNAME { print $2 } ' HOSTNAME="${HOSTNAME}" text1

Still syntax error

---------- Post updated at 02:19 AM ---------- Previous update was at 02:15 AM ----------

nawk -v HOSTNAME=$HOSTNAME ' $1 ~ HOSTNAME { print $2 } ' text1

works for me

Thanks guys

---------- Post updated at 02:19 AM ---------- Previous update was at 02:19 AM ----------

nawk -v HOSTNAME=$HOSTNAME ' $1 ~ HOSTNAME { print $2 } ' text1

works for me

Thanks guys

Do you have nawk?

What is the syntax error?

syntax error as follow:

awk: syntax error near line 1
awk: bailing out near line 1

Probably typo error

command as follow:

awk ' $1 ~ HOSTNAME { print $2 } ' HOSTNAME="${HOSTNAME}" text1

It was a silly question actually, because I could have guessed that!

Anyway you have nawk, so.... bon <something French>! :slight_smile: