Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
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?

share|improve this question
    
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

2 Answers 2

up vote 24 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

share|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 –  TraderJoeChicago 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

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).

share|improve this answer

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.