extract data in bash from url

The name of the pictureThe name of the pictureThe name of the pictureClash 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 = ?










share|improve this question

























    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 = ?










    share|improve this question























      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 = ?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 5 at 16:03









      John Doe

      263




      263




















          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'?





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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'?





            share|improve this answer
























              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'?





              share|improve this answer






















                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'?





                share|improve this answer












                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'?






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 5 at 16:13









                αғsнιη

                16k92563




                16k92563



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Christian Cage

                    How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?