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

command linelinuxtailunix

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

Best Answer

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

cat -n process.logfile | tail

Related Question