Parsing: extract a version from a html line

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I would like to extract version number from this string:



<a href="/url/version/tree/1.0.1alpha11" class="css-truncate">


Note that '/url/version/tree/' may change (ex: from /url/version/tree/ to /url/version2/tree1/) and version may change too (ex: from 1.01alpha11 to 2.0stable)



Ideas/suggestions?







share|improve this question


























    up vote
    0
    down vote

    favorite












    I would like to extract version number from this string:



    <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">


    Note that '/url/version/tree/' may change (ex: from /url/version/tree/ to /url/version2/tree1/) and version may change too (ex: from 1.01alpha11 to 2.0stable)



    Ideas/suggestions?







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I would like to extract version number from this string:



      <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">


      Note that '/url/version/tree/' may change (ex: from /url/version/tree/ to /url/version2/tree1/) and version may change too (ex: from 1.01alpha11 to 2.0stable)



      Ideas/suggestions?







      share|improve this question














      I would like to extract version number from this string:



      <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">


      Note that '/url/version/tree/' may change (ex: from /url/version/tree/ to /url/version2/tree1/) and version may change too (ex: from 1.01alpha11 to 2.0stable)



      Ideas/suggestions?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 14 at 11:38









      Jeff Schaller

      31.8k848109




      31.8k848109










      asked Jan 14 at 10:05









      piplo

      1




      1




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          0
          down vote













          sed solution:



          Sample file input.txt:



          <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
          <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
          <a href="/url/version/tree/2.0stable" class="css-truncate">



          sed -En 's@.*<href="/[^[:space:]]+/([^/"[:space:]]+).*@1@p' input.txt


          The output:



          1.0.1alpha11
          1.0.2alpha11
          2.0stable





          share|improve this answer



























            up vote
            0
            down vote













            I extracted the version by using below awk command. As tested its worked fine.



            Inputfile

            <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
            <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
            <a href="/url/version/tree/2.0stable" class="css-truncate">


            command



            awk -F '[/]' 'print $NF' Inputfile| awk -F '"' 'print $1'


            output



            1.0.1alpha11
            1.0.2alpha11
            2.0stable





            share|improve this answer





























              up vote
              0
              down vote













              Source file: input.txt:



              <a href="/url/version2/tree1/2.0stable" class="css-truncate">
              <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
              <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">


              Using awk and sed:



              awk 'BEGIN FS = "/" print $5 ' input.txt | sed -E 's/^(.*)"s.*/1/'


              Results:



              2.0stable
              1.0.1alpha11
              1.0.2alpha11





              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%2f416993%2fparsing-extract-a-version-from-a-html-line%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                0
                down vote













                sed solution:



                Sample file input.txt:



                <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
                <a href="/url/version/tree/2.0stable" class="css-truncate">



                sed -En 's@.*<href="/[^[:space:]]+/([^/"[:space:]]+).*@1@p' input.txt


                The output:



                1.0.1alpha11
                1.0.2alpha11
                2.0stable





                share|improve this answer
























                  up vote
                  0
                  down vote













                  sed solution:



                  Sample file input.txt:



                  <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                  <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
                  <a href="/url/version/tree/2.0stable" class="css-truncate">



                  sed -En 's@.*<href="/[^[:space:]]+/([^/"[:space:]]+).*@1@p' input.txt


                  The output:



                  1.0.1alpha11
                  1.0.2alpha11
                  2.0stable





                  share|improve this answer






















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    sed solution:



                    Sample file input.txt:



                    <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                    <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
                    <a href="/url/version/tree/2.0stable" class="css-truncate">



                    sed -En 's@.*<href="/[^[:space:]]+/([^/"[:space:]]+).*@1@p' input.txt


                    The output:



                    1.0.1alpha11
                    1.0.2alpha11
                    2.0stable





                    share|improve this answer












                    sed solution:



                    Sample file input.txt:



                    <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                    <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
                    <a href="/url/version/tree/2.0stable" class="css-truncate">



                    sed -En 's@.*<href="/[^[:space:]]+/([^/"[:space:]]+).*@1@p' input.txt


                    The output:



                    1.0.1alpha11
                    1.0.2alpha11
                    2.0stable






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 14 at 11:06









                    RomanPerekhrest

                    22.4k12144




                    22.4k12144






















                        up vote
                        0
                        down vote













                        I extracted the version by using below awk command. As tested its worked fine.



                        Inputfile

                        <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                        <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
                        <a href="/url/version/tree/2.0stable" class="css-truncate">


                        command



                        awk -F '[/]' 'print $NF' Inputfile| awk -F '"' 'print $1'


                        output



                        1.0.1alpha11
                        1.0.2alpha11
                        2.0stable





                        share|improve this answer


























                          up vote
                          0
                          down vote













                          I extracted the version by using below awk command. As tested its worked fine.



                          Inputfile

                          <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                          <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
                          <a href="/url/version/tree/2.0stable" class="css-truncate">


                          command



                          awk -F '[/]' 'print $NF' Inputfile| awk -F '"' 'print $1'


                          output



                          1.0.1alpha11
                          1.0.2alpha11
                          2.0stable





                          share|improve this answer
























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            I extracted the version by using below awk command. As tested its worked fine.



                            Inputfile

                            <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                            <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
                            <a href="/url/version/tree/2.0stable" class="css-truncate">


                            command



                            awk -F '[/]' 'print $NF' Inputfile| awk -F '"' 'print $1'


                            output



                            1.0.1alpha11
                            1.0.2alpha11
                            2.0stable





                            share|improve this answer














                            I extracted the version by using below awk command. As tested its worked fine.



                            Inputfile

                            <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                            <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
                            <a href="/url/version/tree/2.0stable" class="css-truncate">


                            command



                            awk -F '[/]' 'print $NF' Inputfile| awk -F '"' 'print $1'


                            output



                            1.0.1alpha11
                            1.0.2alpha11
                            2.0stable






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jan 14 at 11:28

























                            answered Jan 14 at 11:20









                            Praveen Kumar BS

                            1,010128




                            1,010128




















                                up vote
                                0
                                down vote













                                Source file: input.txt:



                                <a href="/url/version2/tree1/2.0stable" class="css-truncate">
                                <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                                <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">


                                Using awk and sed:



                                awk 'BEGIN FS = "/" print $5 ' input.txt | sed -E 's/^(.*)"s.*/1/'


                                Results:



                                2.0stable
                                1.0.1alpha11
                                1.0.2alpha11





                                share|improve this answer


























                                  up vote
                                  0
                                  down vote













                                  Source file: input.txt:



                                  <a href="/url/version2/tree1/2.0stable" class="css-truncate">
                                  <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                                  <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">


                                  Using awk and sed:



                                  awk 'BEGIN FS = "/" print $5 ' input.txt | sed -E 's/^(.*)"s.*/1/'


                                  Results:



                                  2.0stable
                                  1.0.1alpha11
                                  1.0.2alpha11





                                  share|improve this answer
























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    Source file: input.txt:



                                    <a href="/url/version2/tree1/2.0stable" class="css-truncate">
                                    <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                                    <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">


                                    Using awk and sed:



                                    awk 'BEGIN FS = "/" print $5 ' input.txt | sed -E 's/^(.*)"s.*/1/'


                                    Results:



                                    2.0stable
                                    1.0.1alpha11
                                    1.0.2alpha11





                                    share|improve this answer














                                    Source file: input.txt:



                                    <a href="/url/version2/tree1/2.0stable" class="css-truncate">
                                    <a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
                                    <a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">


                                    Using awk and sed:



                                    awk 'BEGIN FS = "/" print $5 ' input.txt | sed -E 's/^(.*)"s.*/1/'


                                    Results:



                                    2.0stable
                                    1.0.1alpha11
                                    1.0.2alpha11






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jan 14 at 11:52

























                                    answered Jan 14 at 11:46









                                    George Udosen

                                    1,112318




                                    1,112318






















                                         

                                        draft saved


                                        draft discarded


























                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416993%2fparsing-extract-a-version-from-a-html-line%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?

                                        Displaying single band from multi-band raster using QGIS

                                        How many registers does an x86_64 CPU actually have?