How to use command tail -f & show line number.

Hello Guys,
I have created function which is as follow:

tail -f filename |grep "Key word" 
output from this command 
19-11-2011 21:09:15,234 [49087][22830@YU:140649:null] - INFO Numbement - error number:result = :11
19-11-2011 21:09:15,286 [56166][22830@YU:53840:null] - INFO Numbement - error number:result = :11
19-11-2011 21:09:15,523 [146574][22830@YU:237562:null] - INFO Numbement - error number:result = :11
19-11-2011 21:09:16,022 [56166][22830@YU:237562:null] - INFO Numbement - error number:result = :11
19-11-2011 21:09:16,147 [56166][22830@YU:589:null] - INFO Numbement - error number:result = :11
19-11-2011 21:09:16,813 [56166][20030@ananke3:226720:null] - INFO Numbement - error number:result = :11
19-11-2011 21:09:17,823 [44002][20030@ananke3:53821:null] - INFO Numbement - error number:result = :11
19-11-2011 21:09:19,409 [49087][22830@YU:237562:null] - INFO Numbement - error number:result = :11
19-11-2011 21:09:22,367 [44002][20030@ananke3:53821:null] - INFO Numbement - error number:result = :11

[/CODE]I want output :

1    19-11-2011 21:09:15,234 [49087][22830@YU:140649:null] - INFO Numbement - error number:result = :11
2    19-11-2011 21:09:15,286 [56166][22830@YU:53840:null] - INFO Numbement - error number:result = :11
3    19-11-2011 21:09:15,523 [146574][22830@YU:237562:null] - INFO Numbement - error number:result = :11
4    19-11-2011 21:09:16,022 [56166][22830@YU:237562:null] - INFO Numbement - error number:result = :11
5    19-11-2011 21:09:16,147 [56166][22830@YU:589:null] - INFO Numbement - error number:result = :11
6    19-11-2011 21:09:16,813 [56166][20030@ananke3:226720:null] - INFO Numbement - error number:result = :11
7    19-11-2011 21:09:17,823 [44002][20030@ananke3:53821:null] - INFO Numbement - error number:result = :11
8    19-11-2011 21:09:19,409 [49087][22830@YU:237562:null] - INFO Numbement - error number:result = :11
9    19-11-2011 21:09:22,367 [44002][20030@ananke3:53821:null] - INFO Numbement - error number:result = :11

:wall: Please Help Me.:stuck_out_tongue:

Hi,
Try as below
tail -f filename |grep -n "Key word"

Thank. But it's work.
this is output from command :

2    19-11-2011 21:09:15,234 [49087][22830@YU:140649:null] - INFO Numbement - error number:result = :11
3    19-11-2011 21:09:15,286 [56166][22830@YU:53840:null] - INFO Numbement - error number:result = :11
5    19-11-2011 21:09:15,523 [146574][22830@YU:237562:null] - INFO Numbement - error number:result = :11
11    19-11-2011 21:09:16,022 [56166][22830@YU:237562:null] - INFO Numbement - error number:result = :11
12    19-11-2011 21:09:16,147 [56166][22830@YU:589:null] - INFO Numbement - error number:result = :11
20    19-11-2011 21:09:16,813 [56166][20030@ananke3:226720:null] - INFO Numbement - error number:result = :11
25    19-11-2011 21:09:17,823 [44002][20030@ananke3:53821:null] - INFO Numbement - error number:result = :11
33    19-11-2011 21:09:19,409 [49087][22830@YU:237562:null] - INFO Numbement - error number:result = :11
40    19-11-2011 21:09:22,367 [44002][20030@ananke3:53821:null] - INFO Numbement - error number:result = :11

Drop the -n as it counts lines from the input, not matches, and add another process to the pipeline:

tail -f filename |grep  "Key word"|awk '{ printf( "%-5d %s\n", ++c, $0 ); }'

We can eliminate grep...

tail -f filename  | awk '/key word/{print ++c"\t"$0}'

--ahamed

I hate it when I miss little things like that. Good catch.