7

I am trying to tail a user in production log.

Is it possible to use

tail -f grep "username"
alk
  • 68,300
  • 10
  • 92
  • 234
Pawan
  • 29,827
  • 94
  • 242
  • 415

4 Answers4

13

Yes - You use pipe. i.e.

tail -f <some filename> | grep 'username'
Ed Heal
  • 57,599
  • 16
  • 82
  • 120
4

Yes, you can just use a pipe

tail -f fileName | grep username

nakib
  • 4,104
  • 2
  • 26
  • 38
3

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/

Andy Lester
  • 86,927
  • 13
  • 98
  • 148
1

factually I have found it to be more efficient to use: grep username filename | tail