Skip to main content
added 8 characters in body
Source Link
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k
tail -f | nl

works for me and is the first what I thought of - that is if you really want the lines numbered from 1 and not with the real line number from the file watched. Optionally add grep if needed to the appropriate place (either before or after nl). However, remember that buffering may occur. In my particular case, grep has the --line-buffered option, but nl buffers it's output and doesn't have an option to switch that off. Hence the tail | nl | grep combo doesn't really flow nicely.

That said,

tail -f | grep -n pattern

works for me as well. Numbering starts again from the beginning of the "tailing" rather than beginning of the whole log file.

tail -f | nl

works for me and is the first what I thought of - that is if you really want the lines numbered from 1 and not with the real line number from the file watched. Optionally add grep if needed to the appropriate place (either before or after nl). However, remember that buffering may occur. In my particular case, grep has the --line-buffered option, but nl buffers it's output and doesn't have an option to switch that off. Hence the tail | nl | grep combo doesn't really flow nicely.

That said,

tail -f | grep -n

works for me as well. Numbering starts again from the beginning of the "tailing" rather than beginning of the whole log file.

tail -f | nl

works for me and is the first what I thought of - that is if you really want the lines numbered from 1 and not with the real line number from the file watched. Optionally add grep if needed to the appropriate place (either before or after nl). However, remember that buffering may occur. In my particular case, grep has the --line-buffered option, but nl buffers it's output and doesn't have an option to switch that off. Hence the tail | nl | grep combo doesn't really flow nicely.

That said,

tail -f | grep -n pattern

works for me as well. Numbering starts again from the beginning of the "tailing" rather than beginning of the whole log file.

more on buffering
Source Link
peterph
  • 31.5k
  • 3
  • 74
  • 76
tail -f | nl

works for me and is the first what I thought of - that is if you really want the lines numbered from 1 anndand not with the real line number from the file watched. Optionally add grep if needed to the appropriate place (either before or after nl). However, but remember that ifbuffering may buffer the input (i.eoccur. useIn my particular case, grep has the --line-buffered if possible)option, but nl buffers it's output and doesn't have an option to switch that off. Hence the tail | nl | grep combo doesn't really flow nicely.

That said,

tail -f | grep -n

works for me as well. Numbering starts again from the beginning of the "tailing" rather than beginning of the whole log file.

tail -f | nl

works for me - that is if you really want the lines numbered from 1 annd not with the real line number from the file watched. Optionally add grep if needed to the appropriate place (either before or after nl), but remember that if may buffer the input (i.e. use --line-buffered if possible).

tail -f | nl

works for me and is the first what I thought of - that is if you really want the lines numbered from 1 and not with the real line number from the file watched. Optionally add grep if needed to the appropriate place (either before or after nl). However, remember that buffering may occur. In my particular case, grep has the --line-buffered option, but nl buffers it's output and doesn't have an option to switch that off. Hence the tail | nl | grep combo doesn't really flow nicely.

That said,

tail -f | grep -n

works for me as well. Numbering starts again from the beginning of the "tailing" rather than beginning of the whole log file.

Source Link
peterph
  • 31.5k
  • 3
  • 74
  • 76

tail -f | nl

works for me - that is if you really want the lines numbered from 1 annd not with the real line number from the file watched. Optionally add grep if needed to the appropriate place (either before or after nl), but remember that if may buffer the input (i.e. use --line-buffered if possible).