Colored grep output getting fragmented by watch command
up vote
3
down vote
favorite
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
add a comment |
up vote
3
down vote
favorite
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
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
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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
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
grep colors watch
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
add a comment |
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
add a comment |
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 .* *"
add a comment |
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 .* *"
add a comment |
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 .* *"
add a comment |
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 .* *"
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 .* *"
answered Nov 26 at 12:56
Serg Stetsuk
565
565
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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