7

I am trying to tail a user in production log.

Is it possible to use

tail -f grep "username"
alk
  • 69,737
  • 10
  • 105
  • 255
Pawan
  • 31,545
  • 102
  • 256
  • 434

4 Answers4

14

Yes - You use pipe. i.e.

tail -f <some filename> | grep 'username'
Ed Heal
  • 59,252
  • 17
  • 87
  • 127
4

Yes, you can just use a pipe

tail -f fileName | grep username

nakib
  • 4,304
  • 2
  • 28
  • 39
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
  • 91,102
  • 13
  • 100
  • 152
1

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