Timeline for tail -f, but with line numbers
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 27, 2017 at 13:54 | comment | added | Stéphane Chazelas |
@OlivierDulac, about limitations (which don't apply to tail -n +1 here), for regular files, most implementations don't have one as they can start from the end and seek back until they find the nth newline without having to store more than one buf worth of data in memory. For non-seekable input, that's where you can run into limits. POSIX requires implementations to be able to store at least 10 x LINE_MAX bytes (LINE_MAX being at least 2048). GNU tail has no limit other than memory AFAIK
|
|
| Nov 27, 2017 at 13:45 | comment | added | Olivier Dulac | oh, interresting: indeed, the data accumulate into stdin while nothing reads it (between the end of the wc until the start of the head)... I should have realised that. Thx. Now I see why you "<file". clever, as usual :) | |
| Nov 27, 2017 at 13:36 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 67 characters in body
|
| Nov 27, 2017 at 13:35 | comment | added | Stéphane Chazelas |
@OlivierDulac, tail -n +1 (read anything from the start position) addresses the race condition concerns. It will read the lines that were not in the file at the time wc -l terminated, from the exact position wc left it. So NR will have the right position regardless of how many lines have been written in between wc ending and tail starting. It's if you told tail to start from some position relative to the end of the file that you'd have issues.
|
|
| Nov 27, 2017 at 13:10 | comment | added | Olivier Dulac |
choosing l as the variable name made me squint my eyes on $l, thinking it was $1 ^^ (but as I know (and 100% trust) you, I reread and saw the truth). Just for curiosity: to avoid some "race condition" between the wc -l and the tail -f (if the file grows fast, one may discard some lines and thus the NR starts from the wrong number), is it possible to skip $l lines instead? (and what limit is there to tail's -n in posix & in gnu?). Maybe with a temporary intermediate file?
|
|
| Nov 21, 2017 at 18:11 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 6 characters in body
|
| Nov 21, 2017 at 17:36 | history | answered | Stéphane Chazelas | CC BY-SA 3.0 |