How can I extract the ip address and the country and put them individual in a string without any quotes or any other characters which are present in the text by using the next command:

info_ip=`wget --tries=1 --timeout=10 -qO- http://ipinfo.io/?callback=callback; echo`

$ip = ?

$country = ?

1 Answer 1


You can use awk to catch the ip and country and save into an array:

IP_country=( $(awk -F'[:"]' '/ip/ || /country/{ print $5}' <<<"$( wget ... )") )

Then first element is ip and the next is country:

printf '%s\n' "${IP_country[0]}"
printf '%s\n' "${IP_country[1]}"

Or to print all elements:

printf '%s\n' "${IP_country[@]}"

Future reading:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .