Search code examples
greptail

tail using Grep: Filter certain no. of lines from the log file when ever there is a match on the grep


Lets say, i want to grep a log file using a string "xyz" like below.

tail -f filename | grep -vw "xyz"

In this case "xyz" is the keyword that i am searching for. And this will filter the lines from the log file which have the words matching "xyz".

I would also like to filter out the next 10 lines from the log file when ever a line matches in the log file for the keyword "xyz". How can i achieve that?

Please help!


Solution

  • You can use sed to achieve this.

    sed -e '/xyz/,+10d' filename