World World - 1 month ago 9
Linux Question

Bash- how to read the second-to-last line in a file?

I have a file that has the following as the last three lines. I want to retrieve the penultimate line, i.e.

100.000;8438; 06:46:12
.

.
.
.
99.900; 8423; 06:44:41
100.000;8438; 06:46:12
Number of patterns: 8438


I don't know the line number. How can I retrieve it using a shell script? Thanks in advance for your help.

Answer

Try this:

tail -2 yourfile | head -1
Comments