The following command
grep -w '^[^#]* machine_VIP' /etc/hosts | head -1 | awk '{print $1}'
works fine on linux (its capture the machine_VIP alias and return the IP address from /etc/hosts and ignore remarks lines)
Example
cat /etc/hosts
5.5.5.5 GH_T T1 T2 T3 # machine_VIP # 198.2.3.12 MON1 MON2 machine_VIP 18.2.4.12 W1 # machine_VIP # machine_VIP # machine_VIP 192.9.200.77 machine_linux1 machine_linux2 machine_VIP 192.9.200.78 machine_linux10 machine_linux20 machine_VIP_test
grep -w '^[^#]* machine_VIP' /etc/hosts | head -1 | awk '{print $1}'
192.9.200.77
but on Solaris I have the same hosts and when I run the command I not get anything on the output.
So how to fit the command to Solaris?
head -1
? Withouthead -1
in your example the result is the same.