How to read the second-to-last line in a file using Bash?
A short sed one-liner inspired by https://stackoverflow.com/a/7671772/5287901
sed -n 'x;$p'
Explanation:
-n
quiet mode: dont automatically print the pattern spacex
: exchange the pattern space and the hold space (hold space now store the current line, and pattern space the previous line, if any)$
: on the last line,p
: print the pattern space (the previous line, which in this case is the penultimate line).
Try this:
tail -2 yourfile | head -1