How do I tell grep after piping from cat to only highlight numerals greater than 720, or perhaps, more than...












1















It's a fairly simple question. If you would like to include additionally useful information about using grep in this manner, feel free.










share|improve this question























  • What do you mean by highlight, show all lines and just have those numbers in color, or just show those lines with numbers and have the numbers colored, or only show the numbers without any other text? Besides, grep can read from files too, you usually don't need cat in combination with grep.

    – Byte Commander
    Jan 21 at 11:13











  • Regexp should be [0-9]*[7-9][0-9][0-9] for four digits numbers

    – LeonidMew
    Jan 21 at 11:17






  • 1





    To accurately answer your question, please provide an example of what your input looks like.

    – Sergiy Kolodyazhnyy
    Jan 21 at 11:58
















1















It's a fairly simple question. If you would like to include additionally useful information about using grep in this manner, feel free.










share|improve this question























  • What do you mean by highlight, show all lines and just have those numbers in color, or just show those lines with numbers and have the numbers colored, or only show the numbers without any other text? Besides, grep can read from files too, you usually don't need cat in combination with grep.

    – Byte Commander
    Jan 21 at 11:13











  • Regexp should be [0-9]*[7-9][0-9][0-9] for four digits numbers

    – LeonidMew
    Jan 21 at 11:17






  • 1





    To accurately answer your question, please provide an example of what your input looks like.

    – Sergiy Kolodyazhnyy
    Jan 21 at 11:58














1












1








1








It's a fairly simple question. If you would like to include additionally useful information about using grep in this manner, feel free.










share|improve this question














It's a fairly simple question. If you would like to include additionally useful information about using grep in this manner, feel free.







bash grep sort






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 21 at 11:09









RulentRulent

83




83













  • What do you mean by highlight, show all lines and just have those numbers in color, or just show those lines with numbers and have the numbers colored, or only show the numbers without any other text? Besides, grep can read from files too, you usually don't need cat in combination with grep.

    – Byte Commander
    Jan 21 at 11:13











  • Regexp should be [0-9]*[7-9][0-9][0-9] for four digits numbers

    – LeonidMew
    Jan 21 at 11:17






  • 1





    To accurately answer your question, please provide an example of what your input looks like.

    – Sergiy Kolodyazhnyy
    Jan 21 at 11:58



















  • What do you mean by highlight, show all lines and just have those numbers in color, or just show those lines with numbers and have the numbers colored, or only show the numbers without any other text? Besides, grep can read from files too, you usually don't need cat in combination with grep.

    – Byte Commander
    Jan 21 at 11:13











  • Regexp should be [0-9]*[7-9][0-9][0-9] for four digits numbers

    – LeonidMew
    Jan 21 at 11:17






  • 1





    To accurately answer your question, please provide an example of what your input looks like.

    – Sergiy Kolodyazhnyy
    Jan 21 at 11:58

















What do you mean by highlight, show all lines and just have those numbers in color, or just show those lines with numbers and have the numbers colored, or only show the numbers without any other text? Besides, grep can read from files too, you usually don't need cat in combination with grep.

– Byte Commander
Jan 21 at 11:13





What do you mean by highlight, show all lines and just have those numbers in color, or just show those lines with numbers and have the numbers colored, or only show the numbers without any other text? Besides, grep can read from files too, you usually don't need cat in combination with grep.

– Byte Commander
Jan 21 at 11:13













Regexp should be [0-9]*[7-9][0-9][0-9] for four digits numbers

– LeonidMew
Jan 21 at 11:17





Regexp should be [0-9]*[7-9][0-9][0-9] for four digits numbers

– LeonidMew
Jan 21 at 11:17




1




1





To accurately answer your question, please provide an example of what your input looks like.

– Sergiy Kolodyazhnyy
Jan 21 at 11:58





To accurately answer your question, please provide an example of what your input looks like.

– Sergiy Kolodyazhnyy
Jan 21 at 11:58










1 Answer
1






active

oldest

votes


















1














Assuming that by "highlighting numbers greater than 720" you mean that you want to see the full text, but those numbers highlighted with color in the terminal output. I'll further assume that such numbers should also be highlighted if they are part of a word, or otherwise prefixed or suffixed with anything non-numeric (including negation signs or decimal points). However, leading zeroes will not be part of a match.



That said, you can try the regular expression ^|[1-9]d{3,}|[89]d{2}|7[2-9]d after enable PCRE-compatible expressions in grep with the -P switch. Here's an example output, reading from a file example.txt, with the highlighted parts in bold:



$ grep -P '^|[1-9]d{3,}|[89]d{2}|7[2-9]d' example.txt

something
foo 123 42 1111 777 719 720 1000000
321 -6666 bar999 8383m x1425y 52411.0 00013


The used regular expression consists of multiple parts that are joined together with a pipe (|), which means that it matches if any of these parts matches:





  • ^ simply matches at the beginning of each line, without actually consuming any character. This is added to also show all other lines without appropriate numbers in the output, but without highlighting any part of those lines.


  • [1-9]d{3,} matches a single digit in the range 1-9 (no leading zero) followed by at least three or more arbitrary digits (d is equivalent to [0-9]). This rule matches all numbers greater than or equal to 1000.


  • [89]d{2} matches a number starting with an 8 or 9 followed by exactly two more arbitrary digits. This matches all numbers from 800 to 999.


  • 7[2-9]d matches a number starting with a 7 followed by a single digit in the range 2-9 and another single arbitrary digit. That covers all numbers from 720 to 799.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    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%2faskubuntu.com%2fquestions%2f1111617%2fhow-do-i-tell-grep-after-piping-from-cat-to-only-highlight-numerals-greater-than%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Assuming that by "highlighting numbers greater than 720" you mean that you want to see the full text, but those numbers highlighted with color in the terminal output. I'll further assume that such numbers should also be highlighted if they are part of a word, or otherwise prefixed or suffixed with anything non-numeric (including negation signs or decimal points). However, leading zeroes will not be part of a match.



    That said, you can try the regular expression ^|[1-9]d{3,}|[89]d{2}|7[2-9]d after enable PCRE-compatible expressions in grep with the -P switch. Here's an example output, reading from a file example.txt, with the highlighted parts in bold:



    $ grep -P '^|[1-9]d{3,}|[89]d{2}|7[2-9]d' example.txt

    something
    foo 123 42 1111 777 719 720 1000000
    321 -6666 bar999 8383m x1425y 52411.0 00013


    The used regular expression consists of multiple parts that are joined together with a pipe (|), which means that it matches if any of these parts matches:





    • ^ simply matches at the beginning of each line, without actually consuming any character. This is added to also show all other lines without appropriate numbers in the output, but without highlighting any part of those lines.


    • [1-9]d{3,} matches a single digit in the range 1-9 (no leading zero) followed by at least three or more arbitrary digits (d is equivalent to [0-9]). This rule matches all numbers greater than or equal to 1000.


    • [89]d{2} matches a number starting with an 8 or 9 followed by exactly two more arbitrary digits. This matches all numbers from 800 to 999.


    • 7[2-9]d matches a number starting with a 7 followed by a single digit in the range 2-9 and another single arbitrary digit. That covers all numbers from 720 to 799.






    share|improve this answer




























      1














      Assuming that by "highlighting numbers greater than 720" you mean that you want to see the full text, but those numbers highlighted with color in the terminal output. I'll further assume that such numbers should also be highlighted if they are part of a word, or otherwise prefixed or suffixed with anything non-numeric (including negation signs or decimal points). However, leading zeroes will not be part of a match.



      That said, you can try the regular expression ^|[1-9]d{3,}|[89]d{2}|7[2-9]d after enable PCRE-compatible expressions in grep with the -P switch. Here's an example output, reading from a file example.txt, with the highlighted parts in bold:



      $ grep -P '^|[1-9]d{3,}|[89]d{2}|7[2-9]d' example.txt

      something
      foo 123 42 1111 777 719 720 1000000
      321 -6666 bar999 8383m x1425y 52411.0 00013


      The used regular expression consists of multiple parts that are joined together with a pipe (|), which means that it matches if any of these parts matches:





      • ^ simply matches at the beginning of each line, without actually consuming any character. This is added to also show all other lines without appropriate numbers in the output, but without highlighting any part of those lines.


      • [1-9]d{3,} matches a single digit in the range 1-9 (no leading zero) followed by at least three or more arbitrary digits (d is equivalent to [0-9]). This rule matches all numbers greater than or equal to 1000.


      • [89]d{2} matches a number starting with an 8 or 9 followed by exactly two more arbitrary digits. This matches all numbers from 800 to 999.


      • 7[2-9]d matches a number starting with a 7 followed by a single digit in the range 2-9 and another single arbitrary digit. That covers all numbers from 720 to 799.






      share|improve this answer


























        1












        1








        1







        Assuming that by "highlighting numbers greater than 720" you mean that you want to see the full text, but those numbers highlighted with color in the terminal output. I'll further assume that such numbers should also be highlighted if they are part of a word, or otherwise prefixed or suffixed with anything non-numeric (including negation signs or decimal points). However, leading zeroes will not be part of a match.



        That said, you can try the regular expression ^|[1-9]d{3,}|[89]d{2}|7[2-9]d after enable PCRE-compatible expressions in grep with the -P switch. Here's an example output, reading from a file example.txt, with the highlighted parts in bold:



        $ grep -P '^|[1-9]d{3,}|[89]d{2}|7[2-9]d' example.txt

        something
        foo 123 42 1111 777 719 720 1000000
        321 -6666 bar999 8383m x1425y 52411.0 00013


        The used regular expression consists of multiple parts that are joined together with a pipe (|), which means that it matches if any of these parts matches:





        • ^ simply matches at the beginning of each line, without actually consuming any character. This is added to also show all other lines without appropriate numbers in the output, but without highlighting any part of those lines.


        • [1-9]d{3,} matches a single digit in the range 1-9 (no leading zero) followed by at least three or more arbitrary digits (d is equivalent to [0-9]). This rule matches all numbers greater than or equal to 1000.


        • [89]d{2} matches a number starting with an 8 or 9 followed by exactly two more arbitrary digits. This matches all numbers from 800 to 999.


        • 7[2-9]d matches a number starting with a 7 followed by a single digit in the range 2-9 and another single arbitrary digit. That covers all numbers from 720 to 799.






        share|improve this answer













        Assuming that by "highlighting numbers greater than 720" you mean that you want to see the full text, but those numbers highlighted with color in the terminal output. I'll further assume that such numbers should also be highlighted if they are part of a word, or otherwise prefixed or suffixed with anything non-numeric (including negation signs or decimal points). However, leading zeroes will not be part of a match.



        That said, you can try the regular expression ^|[1-9]d{3,}|[89]d{2}|7[2-9]d after enable PCRE-compatible expressions in grep with the -P switch. Here's an example output, reading from a file example.txt, with the highlighted parts in bold:



        $ grep -P '^|[1-9]d{3,}|[89]d{2}|7[2-9]d' example.txt

        something
        foo 123 42 1111 777 719 720 1000000
        321 -6666 bar999 8383m x1425y 52411.0 00013


        The used regular expression consists of multiple parts that are joined together with a pipe (|), which means that it matches if any of these parts matches:





        • ^ simply matches at the beginning of each line, without actually consuming any character. This is added to also show all other lines without appropriate numbers in the output, but without highlighting any part of those lines.


        • [1-9]d{3,} matches a single digit in the range 1-9 (no leading zero) followed by at least three or more arbitrary digits (d is equivalent to [0-9]). This rule matches all numbers greater than or equal to 1000.


        • [89]d{2} matches a number starting with an 8 or 9 followed by exactly two more arbitrary digits. This matches all numbers from 800 to 999.


        • 7[2-9]d matches a number starting with a 7 followed by a single digit in the range 2-9 and another single arbitrary digit. That covers all numbers from 720 to 799.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 21 at 11:54









        Byte CommanderByte Commander

        64.7k27178298




        64.7k27178298






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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%2faskubuntu.com%2fquestions%2f1111617%2fhow-do-i-tell-grep-after-piping-from-cat-to-only-highlight-numerals-greater-than%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

            Human spaceflight

            Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

            File:DeusFollowingSea.jpg