extract data in bash from url
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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 = ?
bash
add a comment |Â
up vote
0
down vote
favorite
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 = ?
bash
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 = ?
bash
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 = ?
bash
bash
asked Sep 5 at 16:03
John Doe
263
263
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You can use awk
to catch the ip
and country
and save into an array:
IFS=$'n'
IP_country=( $(awk -F'[:"]' '/ip/ || /country/ print $5' <<<"$( wget ... )") )
Then first element is ip
and the next is country
:
printf '%sn' "$IP_country[0]"
1.2.3.4
printf '%sn' "$IP_country[1]"
IR
Or to print all elements:
printf '%sn' "$IP_country[@]"
1.2.3.4
IR
Future reading:
- Is it a sane approach to "back up" the $IFS variable?
- What is the 'IFS'?
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You can use awk
to catch the ip
and country
and save into an array:
IFS=$'n'
IP_country=( $(awk -F'[:"]' '/ip/ || /country/ print $5' <<<"$( wget ... )") )
Then first element is ip
and the next is country
:
printf '%sn' "$IP_country[0]"
1.2.3.4
printf '%sn' "$IP_country[1]"
IR
Or to print all elements:
printf '%sn' "$IP_country[@]"
1.2.3.4
IR
Future reading:
- Is it a sane approach to "back up" the $IFS variable?
- What is the 'IFS'?
add a comment |Â
up vote
2
down vote
accepted
You can use awk
to catch the ip
and country
and save into an array:
IFS=$'n'
IP_country=( $(awk -F'[:"]' '/ip/ || /country/ print $5' <<<"$( wget ... )") )
Then first element is ip
and the next is country
:
printf '%sn' "$IP_country[0]"
1.2.3.4
printf '%sn' "$IP_country[1]"
IR
Or to print all elements:
printf '%sn' "$IP_country[@]"
1.2.3.4
IR
Future reading:
- Is it a sane approach to "back up" the $IFS variable?
- What is the 'IFS'?
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You can use awk
to catch the ip
and country
and save into an array:
IFS=$'n'
IP_country=( $(awk -F'[:"]' '/ip/ || /country/ print $5' <<<"$( wget ... )") )
Then first element is ip
and the next is country
:
printf '%sn' "$IP_country[0]"
1.2.3.4
printf '%sn' "$IP_country[1]"
IR
Or to print all elements:
printf '%sn' "$IP_country[@]"
1.2.3.4
IR
Future reading:
- Is it a sane approach to "back up" the $IFS variable?
- What is the 'IFS'?
You can use awk
to catch the ip
and country
and save into an array:
IFS=$'n'
IP_country=( $(awk -F'[:"]' '/ip/ || /country/ print $5' <<<"$( wget ... )") )
Then first element is ip
and the next is country
:
printf '%sn' "$IP_country[0]"
1.2.3.4
printf '%sn' "$IP_country[1]"
IR
Or to print all elements:
printf '%sn' "$IP_country[@]"
1.2.3.4
IR
Future reading:
- Is it a sane approach to "back up" the $IFS variable?
- What is the 'IFS'?
answered Sep 5 at 16:13
ñÃÂsýù÷
16k92563
16k92563
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f467067%2fextract-data-in-bash-from-url%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password