0

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?

roaima
  • 107,089
  • 14
  • 139
  • 261
Zorgan
  • 135
  • 1
  • 7

3 Answers3

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

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
2
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).

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Kyrie001
  • 53
  • 4
1

Yo can do this:

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