validate against a file

Hello all,
I am having problem in writing a if condition for the following:
I have a file Instance.dat which has:
#Server Environment
server1 dev
server2 dev
server3 sit

#!/bin/ksh
ENV=dev
for i in $( cat Instances.dat | grep -v '#' |awk {'print $2'} )
do
  if [[ $ENV = $i ]]
    echo "You are deploying the application in $ENV Environment"
    cat Instances.dat | grep -i $ENV | awk {'print$1'} | grep -v '#' > hostnames.dat
  else
    echo "Please check the Environment"
    exit
  fi
done

Idea is to validate the Env provided in the script against the file but my script doesn't work?? :frowning:
I really appreciate help on this.

Thanks
Chiru

if [[ $ENV = $i ]] ; then

wow! I'm speechless!

Vgresh,

I haven't tried this script but can you please let me know why u are speechless?

Thanks

nawk -v env="${ENV}"  'tolower(env) ~ tolower($0) && /[^#]/ {print $1}' Instances.dat > hostnames.dat

it's called UUOC

:eek:

Thankyou !!!

vgersh99 !!
I didn't get what you did but I am sure it will work.
But when I just cut/pasted the command, it throws error.
I don't have nawk...Does it have to necessarily nawk ??
A lil' explanation is also appreciated..

Chiru

try 'awk' or 'gawk' instead of 'nawk'