grep or other regexp to get value of output












0














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



























    0














    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

























      0












      0








      0


      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






















          3 Answers
          3






          active

          oldest

          votes


















          0














          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





























            0














            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































              0














              This is very simplistic, assuming that the string 'Minimum:' occurs exactly once in your input:



              awk '/Minimum:/ {print $2}'





              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',
                autoActivateHeartbeat: false,
                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

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                0














                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


























                  0














                  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
























                    0












                    0








                    0






                    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,40591226




                    3,40591226

























                        0














                        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




























                          0














                          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


























                            0












                            0








                            0






                            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,5883718




                            3,5883718























                                0














                                This is very simplistic, assuming that the string 'Minimum:' occurs exactly once in your input:



                                awk '/Minimum:/ {print $2}'





                                share|improve this answer


























                                  0














                                  This is very simplistic, assuming that the string 'Minimum:' occurs exactly once in your input:



                                  awk '/Minimum:/ {print $2}'





                                  share|improve this answer
























                                    0












                                    0








                                    0






                                    This is very simplistic, assuming that the string 'Minimum:' occurs exactly once in your input:



                                    awk '/Minimum:/ {print $2}'





                                    share|improve this answer












                                    This is very simplistic, assuming that the string 'Minimum:' occurs exactly once in your input:



                                    awk '/Minimum:/ {print $2}'






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 2 days ago









                                    Jim L.

                                    913




                                    913






























                                        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

                                        Plaza Victoria

                                        Brian Clough

                                        Cáceres