sed hanging

/bin/sed -n '$q;5633653,0 p' lfile 

lfile is a log file that is being updated several times a second.

so, the command above figures out the line number it wants in the lfile and then proceeds to output all lines from that line number to the end of the file.

the problem is, the end of the file is not known because, as i said, the log file gets updated with many more lines every second.

so if the sed command figures out there are 5650000 lines in lfile right now, when it starts running the above command, and while running it, there are no longer 5650000 lines anymore in the lfile. that number has increased. so the sed command hangs.

is there a better way to run the above command?

try:

sed -n ''$line',$p' lfile

Where $line is line number to start to print.

1 Like

Wouldn't tail -f (-F) do that job - and better - for you?

1 Like