Colored grep output getting fragmented by watch command











up vote
3
down vote

favorite
1












I'm trying to run watch, so that it shows me the output from my grep command, while I am running over files and changing things.



The usual way of doing this works fine, but lacks colors:



watch grep 'something' **/*


...and since I do want colors, I did this:



watch grep 'something' **/* --color=always


It's still ugly, because watch doesn't parse the escape codes that make the colors work. So then I found this:



watch --color grep 'something' **/* --color=always


And well... it doesn't work. The output is fragmented / mixed up in some weird way. It shows me only a single line for some reason, while without watch --color the grep outputs about 20.



How can I make watch work with colorized output from grep?





Isolated case:



Using the following:



mkdir grep_test; cd grep_test
echo "asdsadnasdasdnsaasdasd" > file1
echo "testn123ntest" > file2


I create two files, and run the following command:



grep test * --color=always


Which works as expected, and outputs (with colors and whatnot):



file2:test
file2:test


But when I use watch:



watch --color 'grep test * --color=always'


It outputs nothing. Without the --color option it shows the right output, though without the ANSI escapes interpreted.
I'm running this on Fedora 25, in tmux session with zsh inside.



Also, watch -v output is:



watch from procps-ng 3.3.10









share|improve this question
























  • Works fine on my system. Please edit your question and give us an example we can test. Try to reproduce the problem with as few simple input files as possible that we can set up on our machines and see if it works.
    – terdon
    Feb 21 '17 at 11:37










  • @terdon There you go.
    – Błażej Michalik
    Feb 21 '17 at 11:46















up vote
3
down vote

favorite
1












I'm trying to run watch, so that it shows me the output from my grep command, while I am running over files and changing things.



The usual way of doing this works fine, but lacks colors:



watch grep 'something' **/*


...and since I do want colors, I did this:



watch grep 'something' **/* --color=always


It's still ugly, because watch doesn't parse the escape codes that make the colors work. So then I found this:



watch --color grep 'something' **/* --color=always


And well... it doesn't work. The output is fragmented / mixed up in some weird way. It shows me only a single line for some reason, while without watch --color the grep outputs about 20.



How can I make watch work with colorized output from grep?





Isolated case:



Using the following:



mkdir grep_test; cd grep_test
echo "asdsadnasdasdnsaasdasd" > file1
echo "testn123ntest" > file2


I create two files, and run the following command:



grep test * --color=always


Which works as expected, and outputs (with colors and whatnot):



file2:test
file2:test


But when I use watch:



watch --color 'grep test * --color=always'


It outputs nothing. Without the --color option it shows the right output, though without the ANSI escapes interpreted.
I'm running this on Fedora 25, in tmux session with zsh inside.



Also, watch -v output is:



watch from procps-ng 3.3.10









share|improve this question
























  • Works fine on my system. Please edit your question and give us an example we can test. Try to reproduce the problem with as few simple input files as possible that we can set up on our machines and see if it works.
    – terdon
    Feb 21 '17 at 11:37










  • @terdon There you go.
    – Błażej Michalik
    Feb 21 '17 at 11:46













up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





I'm trying to run watch, so that it shows me the output from my grep command, while I am running over files and changing things.



The usual way of doing this works fine, but lacks colors:



watch grep 'something' **/*


...and since I do want colors, I did this:



watch grep 'something' **/* --color=always


It's still ugly, because watch doesn't parse the escape codes that make the colors work. So then I found this:



watch --color grep 'something' **/* --color=always


And well... it doesn't work. The output is fragmented / mixed up in some weird way. It shows me only a single line for some reason, while without watch --color the grep outputs about 20.



How can I make watch work with colorized output from grep?





Isolated case:



Using the following:



mkdir grep_test; cd grep_test
echo "asdsadnasdasdnsaasdasd" > file1
echo "testn123ntest" > file2


I create two files, and run the following command:



grep test * --color=always


Which works as expected, and outputs (with colors and whatnot):



file2:test
file2:test


But when I use watch:



watch --color 'grep test * --color=always'


It outputs nothing. Without the --color option it shows the right output, though without the ANSI escapes interpreted.
I'm running this on Fedora 25, in tmux session with zsh inside.



Also, watch -v output is:



watch from procps-ng 3.3.10









share|improve this question















I'm trying to run watch, so that it shows me the output from my grep command, while I am running over files and changing things.



The usual way of doing this works fine, but lacks colors:



watch grep 'something' **/*


...and since I do want colors, I did this:



watch grep 'something' **/* --color=always


It's still ugly, because watch doesn't parse the escape codes that make the colors work. So then I found this:



watch --color grep 'something' **/* --color=always


And well... it doesn't work. The output is fragmented / mixed up in some weird way. It shows me only a single line for some reason, while without watch --color the grep outputs about 20.



How can I make watch work with colorized output from grep?





Isolated case:



Using the following:



mkdir grep_test; cd grep_test
echo "asdsadnasdasdnsaasdasd" > file1
echo "testn123ntest" > file2


I create two files, and run the following command:



grep test * --color=always


Which works as expected, and outputs (with colors and whatnot):



file2:test
file2:test


But when I use watch:



watch --color 'grep test * --color=always'


It outputs nothing. Without the --color option it shows the right output, though without the ANSI escapes interpreted.
I'm running this on Fedora 25, in tmux session with zsh inside.



Also, watch -v output is:



watch from procps-ng 3.3.10






grep colors watch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 21 '17 at 13:28









Jeff Schaller

37k1052121




37k1052121










asked Feb 21 '17 at 11:32









Błażej Michalik

1537




1537












  • Works fine on my system. Please edit your question and give us an example we can test. Try to reproduce the problem with as few simple input files as possible that we can set up on our machines and see if it works.
    – terdon
    Feb 21 '17 at 11:37










  • @terdon There you go.
    – Błażej Michalik
    Feb 21 '17 at 11:46


















  • Works fine on my system. Please edit your question and give us an example we can test. Try to reproduce the problem with as few simple input files as possible that we can set up on our machines and see if it works.
    – terdon
    Feb 21 '17 at 11:37










  • @terdon There you go.
    – Błażej Michalik
    Feb 21 '17 at 11:46
















Works fine on my system. Please edit your question and give us an example we can test. Try to reproduce the problem with as few simple input files as possible that we can set up on our machines and see if it works.
– terdon
Feb 21 '17 at 11:37




Works fine on my system. Please edit your question and give us an example we can test. Try to reproduce the problem with as few simple input files as possible that we can set up on our machines and see if it works.
– terdon
Feb 21 '17 at 11:37












@terdon There you go.
– Błażej Michalik
Feb 21 '17 at 11:46




@terdon There you go.
– Błażej Michalik
Feb 21 '17 at 11:46










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










It turns out that watch does work with color output. But specifically for grep you should make some workaround (according to grep --color adds ANSI code ESC[K - This can change displayed text)



watch --color "GREP_COLORS=ne grep --color=always .* *"





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: 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%2f346547%2fcolored-grep-output-getting-fragmented-by-watch-command%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








    up vote
    2
    down vote



    accepted










    It turns out that watch does work with color output. But specifically for grep you should make some workaround (according to grep --color adds ANSI code ESC[K - This can change displayed text)



    watch --color "GREP_COLORS=ne grep --color=always .* *"





    share|improve this answer

























      up vote
      2
      down vote



      accepted










      It turns out that watch does work with color output. But specifically for grep you should make some workaround (according to grep --color adds ANSI code ESC[K - This can change displayed text)



      watch --color "GREP_COLORS=ne grep --color=always .* *"





      share|improve this answer























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        It turns out that watch does work with color output. But specifically for grep you should make some workaround (according to grep --color adds ANSI code ESC[K - This can change displayed text)



        watch --color "GREP_COLORS=ne grep --color=always .* *"





        share|improve this answer












        It turns out that watch does work with color output. But specifically for grep you should make some workaround (according to grep --color adds ANSI code ESC[K - This can change displayed text)



        watch --color "GREP_COLORS=ne grep --color=always .* *"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 at 12:56









        Serg Stetsuk

        565




        565






























            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.





            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%2funix.stackexchange.com%2fquestions%2f346547%2fcolored-grep-output-getting-fragmented-by-watch-command%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

            Morgemoulin

            Scott Moir

            Souastre