This question already has an answer here:

Say I want to go to the 80th last line of my file celery.log, but I don't know how many lines it has.

The equivalent of the tail command but go to the 80th line from the end instead of the default.

How would I do this?

marked as duplicate by Kusalananda, αғsнιη, Jeff Schaller, Satō Katsura, Kiwy May 9 '18 at 7:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    What do you mean by "go to"? – Kusalananda May 8 '18 at 7:26
  • The equivilant of tail command but go to the 80th last line instead of the default. – Zorgan May 8 '18 at 7:27
  • 4
    like tail -n80 celery.log ? – Charles May 8 '18 at 7:29
echo '$-79p' | ed -s celery.log

This would run the ed script $-79p on the file called celery.log, which would display the line that is 79 lines up from the last line of the file.

In a shell that understands here-strings:

ed -s celery.log <<<'$-79p'

If the file has less than 80 lines, ed will return an error (the character ? on its standard error stream) and produce no output on the standard output stream.

tail -n 80 celery.log | head -n 1

This will show the first of the last 80 lines (if the file has fewer than 80 lines, it will show the first line of the file).


Yo can do this:

tac celery.log | sed -n '80p'

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