Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to run this command:

watch -n 1 tail -n 200 log/site_dev.log | grep Doctrine

But it does not run, because "I think" that the grep tries to run on the watch instead of the tail...

Is there a way to do something like

watch -n 1 (tail -n 200 log/site_dev.log | grep Doctrine)

Thanks a lot!

share|improve this question
up vote 97 down vote accepted

Surround the command with quotes

watch -n 1 'tail -n 200 log/site_dev.log | fgrep Doctrine'
share|improve this answer
    
Thanks for this!!! It works fine – TomShreds May 12 '10 at 19:31
    
@TomShreds you should give some internet points to tonylo and accept this answer :) – Malcolm Dec 4 '13 at 22:17

I might be wrong, but wouldn't this achieve the same thing more simply?

tail -f -n 200 log/site_dev.log | grep Doctrine
share|improve this answer
2  
WONDERFUL! :) Thanks that is very good! – TomShreds May 12 '10 at 20:18
3  
I agree this may be more efficient as far as CPU is concerned, but in the context of the topic "Using watch with pipes" it doesn't use watch so isn't an answer. This might be a case of a poor example question as watch and pipes seem to appear frequently not in the context of tail. – tudor Jan 20 '14 at 0:07
    
No, I think you're confusing the means and the end. The user clearly wanted to see Doctrine arriving in a growing file, and when he looked in his toolbox, the only thing he found was watch. What he really needed to know was tail -f. See also meta.stackexchange.com/questions/66377/what-is-the-xy-problem – dland Mar 21 at 11:03
3  
I think these are both acceptable answers. The top and accepted answer correctly answers the exact question posed, and this answer correctly identifies the XY problem that OP created for themselves and provides the solution they really wanted in the first place. Both answers could easily be useful to someone coming across this question. – cdhowie Apr 14 at 16:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.