How to select a number?












0















cat /etc/redhat-release


return:



CentOS Linux release 5.6.1804 (Core)


how do I select the first number I've only tried



cat /etc/redhat-release | awk '{print $4}'


and this gives me back:



5.6.1804


but I just want the first number










share|improve this question





























    0















    cat /etc/redhat-release


    return:



    CentOS Linux release 5.6.1804 (Core)


    how do I select the first number I've only tried



    cat /etc/redhat-release | awk '{print $4}'


    and this gives me back:



    5.6.1804


    but I just want the first number










    share|improve this question



























      0












      0








      0








      cat /etc/redhat-release


      return:



      CentOS Linux release 5.6.1804 (Core)


      how do I select the first number I've only tried



      cat /etc/redhat-release | awk '{print $4}'


      and this gives me back:



      5.6.1804


      but I just want the first number










      share|improve this question
















      cat /etc/redhat-release


      return:



      CentOS Linux release 5.6.1804 (Core)


      how do I select the first number I've only tried



      cat /etc/redhat-release | awk '{print $4}'


      and this gives me back:



      5.6.1804


      but I just want the first number







      bash shell-script shell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 23 at 20:57









      msp9011

      4,27344065




      4,27344065










      asked Jan 23 at 20:34









      ortigaortiga

      83




      83






















          6 Answers
          6






          active

          oldest

          votes


















          0














          $ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
          5


          Need I say more?






          share|improve this answer
























          • perfect thanks..

            – ortiga
            Jan 23 at 20:46











          • @ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.

            – juhist
            Jan 23 at 20:59



















          2














          If your CentOS machine has redhat-lsb or redhat-lsb-core installed:



          lsb_release -sr | cut -d '.' -f 1


          This would get the release version (only) using the lsb_release command and then cut out the bit before the first dot.



          On a 16.04 Ubuntu machine:



          $ lsb_release -sr | cut -d '.' -f 1
          16





          share|improve this answer































            1














            Using awk:



            awk -F '[ .]' '{print $4}' /etc/redhat-release


            Using sed:



            sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release


            Using grep:



            grep -Eo ' [0-9]' /etc/redhat-release





            share|improve this answer


























            • There's also /etc/os-release

              – Sammitch
              Jan 25 at 0:28



















            0














            There are so many ways, here is one of those:



            cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1


            The easier way would be using something that is prepared just for that:



            [user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
            7





            share|improve this answer































              0














              sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.



              Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.



              so you could also use:
              awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.






              share|improve this answer































                0














                I would do something akin to this. On my RH7 box:



                $ cat /etc/redhat-release
                Red Hat Enterprise Linux Server release 7.5 (Maipo)

                $ cut -f 7 -d " " /etc/redhat-release
                7.5

                $ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE

                $ echo $MAJOR $MINOR $RELEASE
                7 5

                $


                Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.






                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',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  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%2f496317%2fhow-to-select-a-number%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  6 Answers
                  6






                  active

                  oldest

                  votes








                  6 Answers
                  6






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  0














                  $ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
                  5


                  Need I say more?






                  share|improve this answer
























                  • perfect thanks..

                    – ortiga
                    Jan 23 at 20:46











                  • @ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.

                    – juhist
                    Jan 23 at 20:59
















                  0














                  $ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
                  5


                  Need I say more?






                  share|improve this answer
























                  • perfect thanks..

                    – ortiga
                    Jan 23 at 20:46











                  • @ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.

                    – juhist
                    Jan 23 at 20:59














                  0












                  0








                  0







                  $ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
                  5


                  Need I say more?






                  share|improve this answer













                  $ echo 'CentOS Linux release 5.6.1804 (Core)'|awk '{print $4}'|awk -F '.' '{print $1}'
                  5


                  Need I say more?







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 23 at 20:38









                  juhistjuhist

                  1333




                  1333













                  • perfect thanks..

                    – ortiga
                    Jan 23 at 20:46











                  • @ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.

                    – juhist
                    Jan 23 at 20:59



















                  • perfect thanks..

                    – ortiga
                    Jan 23 at 20:46











                  • @ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.

                    – juhist
                    Jan 23 at 20:59

















                  perfect thanks..

                  – ortiga
                  Jan 23 at 20:46





                  perfect thanks..

                  – ortiga
                  Jan 23 at 20:46













                  @ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.

                  – juhist
                  Jan 23 at 20:59





                  @ortiga Don't forget to select one answer you like the most and accept it. Personally, I would select the lsb_release answer, but my answer is closest to what you originally did.

                  – juhist
                  Jan 23 at 20:59













                  2














                  If your CentOS machine has redhat-lsb or redhat-lsb-core installed:



                  lsb_release -sr | cut -d '.' -f 1


                  This would get the release version (only) using the lsb_release command and then cut out the bit before the first dot.



                  On a 16.04 Ubuntu machine:



                  $ lsb_release -sr | cut -d '.' -f 1
                  16





                  share|improve this answer




























                    2














                    If your CentOS machine has redhat-lsb or redhat-lsb-core installed:



                    lsb_release -sr | cut -d '.' -f 1


                    This would get the release version (only) using the lsb_release command and then cut out the bit before the first dot.



                    On a 16.04 Ubuntu machine:



                    $ lsb_release -sr | cut -d '.' -f 1
                    16





                    share|improve this answer


























                      2












                      2








                      2







                      If your CentOS machine has redhat-lsb or redhat-lsb-core installed:



                      lsb_release -sr | cut -d '.' -f 1


                      This would get the release version (only) using the lsb_release command and then cut out the bit before the first dot.



                      On a 16.04 Ubuntu machine:



                      $ lsb_release -sr | cut -d '.' -f 1
                      16





                      share|improve this answer













                      If your CentOS machine has redhat-lsb or redhat-lsb-core installed:



                      lsb_release -sr | cut -d '.' -f 1


                      This would get the release version (only) using the lsb_release command and then cut out the bit before the first dot.



                      On a 16.04 Ubuntu machine:



                      $ lsb_release -sr | cut -d '.' -f 1
                      16






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 23 at 20:40









                      KusalanandaKusalananda

                      127k16240395




                      127k16240395























                          1














                          Using awk:



                          awk -F '[ .]' '{print $4}' /etc/redhat-release


                          Using sed:



                          sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release


                          Using grep:



                          grep -Eo ' [0-9]' /etc/redhat-release





                          share|improve this answer


























                          • There's also /etc/os-release

                            – Sammitch
                            Jan 25 at 0:28
















                          1














                          Using awk:



                          awk -F '[ .]' '{print $4}' /etc/redhat-release


                          Using sed:



                          sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release


                          Using grep:



                          grep -Eo ' [0-9]' /etc/redhat-release





                          share|improve this answer


























                          • There's also /etc/os-release

                            – Sammitch
                            Jan 25 at 0:28














                          1












                          1








                          1







                          Using awk:



                          awk -F '[ .]' '{print $4}' /etc/redhat-release


                          Using sed:



                          sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release


                          Using grep:



                          grep -Eo ' [0-9]' /etc/redhat-release





                          share|improve this answer















                          Using awk:



                          awk -F '[ .]' '{print $4}' /etc/redhat-release


                          Using sed:



                          sed -E 's/[ Aa-Zz]*([0-9]+).*/1/' /etc/redhat-release


                          Using grep:



                          grep -Eo ' [0-9]' /etc/redhat-release






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jan 23 at 20:50

























                          answered Jan 23 at 20:41









                          msp9011msp9011

                          4,27344065




                          4,27344065













                          • There's also /etc/os-release

                            – Sammitch
                            Jan 25 at 0:28



















                          • There's also /etc/os-release

                            – Sammitch
                            Jan 25 at 0:28

















                          There's also /etc/os-release

                          – Sammitch
                          Jan 25 at 0:28





                          There's also /etc/os-release

                          – Sammitch
                          Jan 25 at 0:28











                          0














                          There are so many ways, here is one of those:



                          cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1


                          The easier way would be using something that is prepared just for that:



                          [user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
                          7





                          share|improve this answer




























                            0














                            There are so many ways, here is one of those:



                            cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1


                            The easier way would be using something that is prepared just for that:



                            [user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
                            7





                            share|improve this answer


























                              0












                              0








                              0







                              There are so many ways, here is one of those:



                              cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1


                              The easier way would be using something that is prepared just for that:



                              [user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
                              7





                              share|improve this answer













                              There are so many ways, here is one of those:



                              cat /etc/redhat-release | cut -d " " -f4 | cut -d . -f1


                              The easier way would be using something that is prepared just for that:



                              [user@server]$ source /etc/os-release && echo $CENTOS_MANTISBT_PROJECT_VERSION
                              7






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jan 23 at 20:39









                              Dmitriy KupchDmitriy Kupch

                              1012




                              1012























                                  0














                                  sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.



                                  Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.



                                  so you could also use:
                                  awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.






                                  share|improve this answer




























                                    0














                                    sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.



                                    Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.



                                    so you could also use:
                                    awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.






                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.



                                      Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.



                                      so you could also use:
                                      awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.






                                      share|improve this answer













                                      sed -Ee's/^.* ([0-9.]+) .*$/1/' /etc/redhat-release |cut -f1,1 -d.



                                      Sed command extracts the whole version number (same as your AWK, so you could use that as well) and the second extracts the first field from that using '.' as the separator.



                                      so you could also use:
                                      awk '{print $4}' /etc/redhat-release |cut -f1,1 -d.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jan 23 at 20:46









                                      user55614user55614

                                      1




                                      1























                                          0














                                          I would do something akin to this. On my RH7 box:



                                          $ cat /etc/redhat-release
                                          Red Hat Enterprise Linux Server release 7.5 (Maipo)

                                          $ cut -f 7 -d " " /etc/redhat-release
                                          7.5

                                          $ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE

                                          $ echo $MAJOR $MINOR $RELEASE
                                          7 5

                                          $


                                          Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.






                                          share|improve this answer




























                                            0














                                            I would do something akin to this. On my RH7 box:



                                            $ cat /etc/redhat-release
                                            Red Hat Enterprise Linux Server release 7.5 (Maipo)

                                            $ cut -f 7 -d " " /etc/redhat-release
                                            7.5

                                            $ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE

                                            $ echo $MAJOR $MINOR $RELEASE
                                            7 5

                                            $


                                            Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.






                                            share|improve this answer


























                                              0












                                              0








                                              0







                                              I would do something akin to this. On my RH7 box:



                                              $ cat /etc/redhat-release
                                              Red Hat Enterprise Linux Server release 7.5 (Maipo)

                                              $ cut -f 7 -d " " /etc/redhat-release
                                              7.5

                                              $ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE

                                              $ echo $MAJOR $MINOR $RELEASE
                                              7 5

                                              $


                                              Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.






                                              share|improve this answer













                                              I would do something akin to this. On my RH7 box:



                                              $ cat /etc/redhat-release
                                              Red Hat Enterprise Linux Server release 7.5 (Maipo)

                                              $ cut -f 7 -d " " /etc/redhat-release
                                              7.5

                                              $ cut -f 7 -d " " /etc/redhat-release | IFS=. read MAJOR MINOR RELEASE

                                              $ echo $MAJOR $MINOR $RELEASE
                                              7 5

                                              $


                                              Now you have all the components of the build in an env var to be referneced at you leisure. There are more sophisticated ways to get the original data, but I think that's beyond the scope of this question, which is just extracting the components of a dotted version string.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jan 23 at 21:54









                                              GarethHumphriesAccGarethHumphriesAcc

                                              1613




                                              1613






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496317%2fhow-to-select-a-number%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  How to make a Squid Proxy server?

                                                  Is this a new Fibonacci Identity?

                                                  Touch on Surface Book