grep or other regexp to get value of output











up vote
0
down vote

favorite
1












How to use grep or any other tool to get a specific value in an output



In the below output I need to get the value 255.00 in the line with Minimum: 255.00 (1.0000)



A pattern like: Channel Statistics:s+Gray:s+Minimum: +([d.]+)



Image: test.tif
Format: TIFF (Tagged Image File Format)
Geometry: 2525x1785
Class: DirectClass
Type: bilevel
Depth: 1 bits-per-pixel component
Channel Depths:
Gray: 1 bits
Channel Statistics:
Gray:
Minimum: 255.00 (1.0000)
Maximum: 255.00 (1.0000)
Mean: 255.00 (1.0000)
Standard Deviation: 0.00 (0.0000)
Filesize: 581
Interlace: No
Orientation: Unknown
Background Color: white
Border Color: #DFDFDF
Matte Color: #BDBDBD









share|improve this question


























    up vote
    0
    down vote

    favorite
    1












    How to use grep or any other tool to get a specific value in an output



    In the below output I need to get the value 255.00 in the line with Minimum: 255.00 (1.0000)



    A pattern like: Channel Statistics:s+Gray:s+Minimum: +([d.]+)



    Image: test.tif
    Format: TIFF (Tagged Image File Format)
    Geometry: 2525x1785
    Class: DirectClass
    Type: bilevel
    Depth: 1 bits-per-pixel component
    Channel Depths:
    Gray: 1 bits
    Channel Statistics:
    Gray:
    Minimum: 255.00 (1.0000)
    Maximum: 255.00 (1.0000)
    Mean: 255.00 (1.0000)
    Standard Deviation: 0.00 (0.0000)
    Filesize: 581
    Interlace: No
    Orientation: Unknown
    Background Color: white
    Border Color: #DFDFDF
    Matte Color: #BDBDBD









    share|improve this question
























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      How to use grep or any other tool to get a specific value in an output



      In the below output I need to get the value 255.00 in the line with Minimum: 255.00 (1.0000)



      A pattern like: Channel Statistics:s+Gray:s+Minimum: +([d.]+)



      Image: test.tif
      Format: TIFF (Tagged Image File Format)
      Geometry: 2525x1785
      Class: DirectClass
      Type: bilevel
      Depth: 1 bits-per-pixel component
      Channel Depths:
      Gray: 1 bits
      Channel Statistics:
      Gray:
      Minimum: 255.00 (1.0000)
      Maximum: 255.00 (1.0000)
      Mean: 255.00 (1.0000)
      Standard Deviation: 0.00 (0.0000)
      Filesize: 581
      Interlace: No
      Orientation: Unknown
      Background Color: white
      Border Color: #DFDFDF
      Matte Color: #BDBDBD









      share|improve this question













      How to use grep or any other tool to get a specific value in an output



      In the below output I need to get the value 255.00 in the line with Minimum: 255.00 (1.0000)



      A pattern like: Channel Statistics:s+Gray:s+Minimum: +([d.]+)



      Image: test.tif
      Format: TIFF (Tagged Image File Format)
      Geometry: 2525x1785
      Class: DirectClass
      Type: bilevel
      Depth: 1 bits-per-pixel component
      Channel Depths:
      Gray: 1 bits
      Channel Statistics:
      Gray:
      Minimum: 255.00 (1.0000)
      Maximum: 255.00 (1.0000)
      Mean: 255.00 (1.0000)
      Standard Deviation: 0.00 (0.0000)
      Filesize: 581
      Interlace: No
      Orientation: Unknown
      Background Color: white
      Border Color: #DFDFDF
      Matte Color: #BDBDBD






      linux debian regex grep






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 1 at 11:24









      clarkk

      941313




      941313






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          Using perl, you can do the following. It captures the numeric value after minimum: inside the block Channel Statistics: and prints it:



          perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file


          Output: (for given example)



          255.00


          Explanation:



          -0      # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
          -n # Iterate over the file
          -e # execute the command line


          Regex:



          /                           # regex delimiter
          Channel Statistics: # literally
          s+ # 1 or more any kind of spaces
          Gray: # literally
          s+ # 1 or more any kind of spaces
          Minimum: # literally
          h+ # 1 or more horizontal spaces
          ( # start group 1
          [d.]+ # 1 or more digit or dot
          ) # end group
          / # regex delimiter





          share|improve this answer




























            up vote
            0
            down vote













            With sed



            sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data


            In slow-mo:





            • -r tells sed we use th extened regexp "syntax"


            • -n tells sed to not print non-matching lines


            • s/^s+Minimum:s+([0-9.]+).+$/1/ matches your target line and replaces it with just the value you are after


            • p tells sed to print the result


            If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:



            sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data


            where:





            • :a;N;$!ba; is a loop in the sed language that loads the whole file at once


            • -n is no longer necessary since there are no other lines we don't want to print

            • the final p is no longer necessary either since we don't use -n






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2fsuperuser.com%2fquestions%2f1379939%2fgrep-or-other-regexp-to-get-value-of-output%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              Using perl, you can do the following. It captures the numeric value after minimum: inside the block Channel Statistics: and prints it:



              perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file


              Output: (for given example)



              255.00


              Explanation:



              -0      # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
              -n # Iterate over the file
              -e # execute the command line


              Regex:



              /                           # regex delimiter
              Channel Statistics: # literally
              s+ # 1 or more any kind of spaces
              Gray: # literally
              s+ # 1 or more any kind of spaces
              Minimum: # literally
              h+ # 1 or more horizontal spaces
              ( # start group 1
              [d.]+ # 1 or more digit or dot
              ) # end group
              / # regex delimiter





              share|improve this answer

























                up vote
                0
                down vote













                Using perl, you can do the following. It captures the numeric value after minimum: inside the block Channel Statistics: and prints it:



                perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file


                Output: (for given example)



                255.00


                Explanation:



                -0      # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
                -n # Iterate over the file
                -e # execute the command line


                Regex:



                /                           # regex delimiter
                Channel Statistics: # literally
                s+ # 1 or more any kind of spaces
                Gray: # literally
                s+ # 1 or more any kind of spaces
                Minimum: # literally
                h+ # 1 or more horizontal spaces
                ( # start group 1
                [d.]+ # 1 or more digit or dot
                ) # end group
                / # regex delimiter





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Using perl, you can do the following. It captures the numeric value after minimum: inside the block Channel Statistics: and prints it:



                  perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file


                  Output: (for given example)



                  255.00


                  Explanation:



                  -0      # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
                  -n # Iterate over the file
                  -e # execute the command line


                  Regex:



                  /                           # regex delimiter
                  Channel Statistics: # literally
                  s+ # 1 or more any kind of spaces
                  Gray: # literally
                  s+ # 1 or more any kind of spaces
                  Minimum: # literally
                  h+ # 1 or more horizontal spaces
                  ( # start group 1
                  [d.]+ # 1 or more digit or dot
                  ) # end group
                  / # regex delimiter





                  share|improve this answer












                  Using perl, you can do the following. It captures the numeric value after minimum: inside the block Channel Statistics: and prints it:



                  perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file


                  Output: (for given example)



                  255.00


                  Explanation:



                  -0      # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
                  -n # Iterate over the file
                  -e # execute the command line


                  Regex:



                  /                           # regex delimiter
                  Channel Statistics: # literally
                  s+ # 1 or more any kind of spaces
                  Gray: # literally
                  s+ # 1 or more any kind of spaces
                  Minimum: # literally
                  h+ # 1 or more horizontal spaces
                  ( # start group 1
                  [d.]+ # 1 or more digit or dot
                  ) # end group
                  / # regex delimiter






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 1 at 13:11









                  Toto

                  3,38691126




                  3,38691126
























                      up vote
                      0
                      down vote













                      With sed



                      sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data


                      In slow-mo:





                      • -r tells sed we use th extened regexp "syntax"


                      • -n tells sed to not print non-matching lines


                      • s/^s+Minimum:s+([0-9.]+).+$/1/ matches your target line and replaces it with just the value you are after


                      • p tells sed to print the result


                      If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:



                      sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data


                      where:





                      • :a;N;$!ba; is a loop in the sed language that loads the whole file at once


                      • -n is no longer necessary since there are no other lines we don't want to print

                      • the final p is no longer necessary either since we don't use -n






                      share|improve this answer



























                        up vote
                        0
                        down vote













                        With sed



                        sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data


                        In slow-mo:





                        • -r tells sed we use th extened regexp "syntax"


                        • -n tells sed to not print non-matching lines


                        • s/^s+Minimum:s+([0-9.]+).+$/1/ matches your target line and replaces it with just the value you are after


                        • p tells sed to print the result


                        If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:



                        sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data


                        where:





                        • :a;N;$!ba; is a loop in the sed language that loads the whole file at once


                        • -n is no longer necessary since there are no other lines we don't want to print

                        • the final p is no longer necessary either since we don't use -n






                        share|improve this answer

























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          With sed



                          sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data


                          In slow-mo:





                          • -r tells sed we use th extened regexp "syntax"


                          • -n tells sed to not print non-matching lines


                          • s/^s+Minimum:s+([0-9.]+).+$/1/ matches your target line and replaces it with just the value you are after


                          • p tells sed to print the result


                          If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:



                          sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data


                          where:





                          • :a;N;$!ba; is a loop in the sed language that loads the whole file at once


                          • -n is no longer necessary since there are no other lines we don't want to print

                          • the final p is no longer necessary either since we don't use -n






                          share|improve this answer














                          With sed



                          sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data


                          In slow-mo:





                          • -r tells sed we use th extened regexp "syntax"


                          • -n tells sed to not print non-matching lines


                          • s/^s+Minimum:s+([0-9.]+).+$/1/ matches your target line and replaces it with just the value you are after


                          • p tells sed to print the result


                          If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:



                          sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data


                          where:





                          • :a;N;$!ba; is a loop in the sed language that loads the whole file at once


                          • -n is no longer necessary since there are no other lines we don't want to print

                          • the final p is no longer necessary either since we don't use -n







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 1 at 17:17

























                          answered Dec 1 at 16:49









                          xenoid

                          3,5783718




                          3,5783718






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • 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%2fsuperuser.com%2fquestions%2f1379939%2fgrep-or-other-regexp-to-get-value-of-output%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

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                              Eduardo VII do Reino Unido