Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to tail a log file that's continuously being written to but would like to exclude various entries that are 'common' so I only see errors, etc. as they are thrown. I can pipe to grep -v "pattern" but would ideally like to use a file containing entries to skip. Any ideas?

share|improve this question

4 Answers 4

The -f option to grep allows one to specify a file containing patterns, one pattern per line. See the grep(1) man page.

In addition, the unbuffer command available on some systems will disable the output buffering that normally occurs in pipelines. The addition of the grep filter may otherwise delay the output of your pipeline. See the unbuffer(1) man page for details.

share|improve this answer
    
You might mention that you need both -f and -v for the given requirements. –  hstoerr Jan 30 '13 at 13:35

You can use grep -v "pattern" like you said. But instead of pattern use

`cat file_with_entires_to_skip`

Remember to include the backtics. So your command would look like:

tail -v FILE | grep -v "`cat FILE_WITH_ENTRIES_TO_SKIP`"
share|improve this answer
    
Make that grep -v "cat FILE_WITH_ENTRIES_TO_SKIP", or the shell will expand special characters in the pattern list. –  Gilles Oct 8 '10 at 23:29
    
You mean grep -v "`cat FILE_WITH_ENTIRES_TO_SKIP`"? (You have to escape backtics in Markdown.) –  Wuffers Oct 8 '10 at 23:33

Use grep -f FILE and it will obtain patterns from that file. See the man page for more information.

share|improve this answer

My grep includes an --exclude-from=FILE option that lets me add exclusion patterns from a file. I've got:

my-macbook-pro:Sun America ianchesal$ grep --version
grep (GNU grep) 2.5.1

So you could do:

tail -f <file> | grep --exclude-from=excludes.txt
share|improve this answer
    
"Skip files whose base name matches any of the file-name globs read from FILE (using wildcard matching as described under --exclude)." So it's for skipping files, not matches –  Janus Troelsen Nov 30 '12 at 1:21

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.