Unix /Linux show the last part of a file with line numbers

5

Is there a way to make tail show a line number in front of the last lines it show so that it show the growth of the file when using it in a script.

e.g: when using it in a script like this one:

while [-z $(ps -p $pid) ]; do
   echo  "process is running"
   .....
   tail process.logfile
   sleep 15
   clear
done

out put should be:

111 line 111
112 line 112
113 line 113
114 line 114
115 line 115
....

and the next round it should be:
116 line 116
117 line 117
118 line 118
119 line 119
120 line 120
...

Erwin

Posted 2013-12-19T11:36:08.980

Reputation: 53

What about using tail -f instead? – choroba – 2013-12-19T11:49:46.063

Answers

5

tail itself doesn't have a line numbering capability, but other utilities do. This is a typical solution:

cat -n process.logfile | tail

jdh

Posted 2013-12-19T11:36:08.980

Reputation: 6 645

Ok I never tought of that! This is somewhat shamefull, form me. Thanks for the quick answer. It is exactly what I need. – Erwin – 2013-12-19T13:17:07.610