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
...

1
  • What about using tail -f instead? – choroba Dec 19 '13 at 11:49
5

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

cat -n process.logfile | tail

1
  • Ok I never tought of that! This is somewhat shamefull, form me. Thanks for the quick answer. It is exactly what I need. – Erwin Dec 19 '13 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.