tail -f path

The above will output modifications to the file instantly, but I want to apply a filter to the output, only show when there is a keyword xxx in it.

How to approach this?

link|improve this question

25% accept rate
Marking answers as accepted helps others who read your questions and their answers to know which answer might be more likely to help them if they have a similar question or problem. You can revisit your earlier questions by clicking on your username. – Dennis Williamson Jul 5 '10 at 9:38
feedback

2 Answers

up vote 13 down vote accepted

With Unix you can pipe the output of oone program into another.

So to filter tail, you can use grep

tail -f path | grep xxx

link|improve this answer
But let's say you have 100 lines in the tail (end of the file), and these lines are the ones you want to filter. Your solution – Sergio Oliveira Jr. Nov 7 '11 at 15:12
1  
If you only want to search the last 100 lines of a file try tail -100 path | grep xxx – AddersUK Nov 25 '11 at 23:19
feedback

and you can use multiple pipes and greps, and exclude things with grep -v, get case insensitivity with grep -i, etc.

i.e.: tail -100f /var/log/messages | grep -V ACPI | grep -i ata

start tailing 100 lines from the end, and keep tailing, first exclude any lines with ACPI, then show lines with ata, ATA, or any mix of those.

Another handy one is the ABC options, for the lines After, Before, and Context (lines before and after).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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