Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make tail display only the lines that have a specific text?

Tags:

shell

unix

tail

How to make tail display only the lines that have a specific text? If the search criteria can be a regular expression, it would be even better. I need something like:

tail -f mylogfile.log showOnlyLinesWith "error: " 

I am running Darwin (Mac OS X) and I'm totally beginner in the bash.

like image 991
blagus Avatar asked Aug 15 '13 19:08

blagus


1 Answers

You can do

tail -f mylogfile.log | grep "error: " 

This works with regular expressions too. In general, you can take the output of any command, add | to "pipe" it to grep, and let grep filter out the lines that don't match a certain pattern.

like image 193
arghbleargh Avatar answered Oct 06 '22 06:10

arghbleargh