Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use tail and grep in combination? [duplicate]

I am trying to tail a user in production log.

Is it possible to use

tail -f grep "username"
like image 684
Pawan Avatar asked Jan 02 '13 14:01

Pawan


3 Answers

Yes - You use pipe. i.e.

tail -f <some filename> | grep 'username'
like image 132
Ed Heal Avatar answered Sep 18 '22 12:09

Ed Heal


Yes, you can just use a pipe

tail -f fileName | grep username

like image 43
nakib Avatar answered Sep 19 '22 12:09

nakib


The ack command, which is a grep-like text finder, has a --passthru flag that is designed specifically for this.

Since ack automatically color codes matches for you, you can use it to search the output of a tailed log file, and highlight the matches, but also see the lines that don't match.

tail -f error.log | ack --passthru whatever

All the lines of the tailed log will show up, but the matches will be highlighted.

ack is at http://beyondgrep.com/

like image 20
Andy Lester Avatar answered Sep 21 '22 12:09

Andy Lester