How do I get the last non-empty line of a file using tail in Bash?
You can use Awk:
awk '/./{line=$0} END{print line}' my_file.txt
This solution has the advantage of using just one tool.
Use tac, so you dont have to read the whole file:
tac FILE |egrep -m 1 .
How about using grep
to filter out the blank lines first?
$ cat rjh
1
2
3
$ grep "." rjh | tail -1
3