print user variable input

this may be basic thing for everyone here, but i cant push awk to print the variable user input which is INS, please help.

code:

INS=$1

printf '\n'
symdg list | grep $INS-clone | awk -v i=$INS '{ID=substr($4,9,4)}{print "Device Group: "$1,"at Array "ID,i}'

output:

$ ./test.sh patty

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

try using nawk

it worked, thanks! what would be difference / specific application wherein nawk is better than awk??

Are you using Solaris..?

As per my findings /usr/pkg4/bin/awk and nawk used in Solaris..

please do let me correct if i am wrong. not familiar with Solaris..:slight_smile:

yes, its Solaris 9

You could also put variables into awk the old-fashioned way:

awk '{...}' VARNAME="$VAR"

You really should be double-quoting all your shell variables, by the way.

Also, if you're using awk, you really don't need grep.

symdg list | awk '$0 ~ I"-clone" { ID=substr($4,9,4); print "Device Group: "$1,"at Array "ID,I}' I="$INS"