AWK not giving me correct output.

i have a line like this in my script

IP=`get_IP <hostname> | awk '{ print $1 }'
echo $IP

the problem is get_IP <hostname> returns data formated as follows:

ip 1.1.1.1 name server_name

the code above returns

1.1.1.1 server_name and i just need the 1.1.1.1

I have tried to add "| cut -d' ' -f1" and "| awk '{ print $1 }'" to the end of the code above, but these still return the same output.

Assuming your sample get_IP output example is exact -

IP=$(get_IP <hostname> | awk '{ print $2 }') 
echo $IP

thats the same thing i have just with backticks instead of $(), still gives me the same output

then try with sed...
search forum you will find many thread to cut only IP address from text..

fixed it: i just add | grep 'ip' | in the middle so it only took the ip line and not the hostname line

if you are using awk make full use of it

awk '/ip/{print $1}'