Can someone here show how to get the last non-blank line from a text file?
Thank you!
Can someone here show how to get the last non-blank line from a text file?
Thank you!
sed '$!d' file.txt
tail -1 file.txt
(sed '$!d' file.txt) doesn't work for me, it returns "sed: Extra characters after command"
(tail -1 file.txt) only give me the last line of the file.txt, but last line or last few lines in file.txt could be empty.
So, I need a way to extract the line in file.txt that has some characters.
awk 'NF{s=$0}END{print s}' file
Regards
That's what I got from awk by running your command:
awK: syntax error near line 1
awk: bailing out near line 1
Use nawk or /usr/xpg4/bin/awk on Solaris ...
Not the most eligant but it works:
sed -e '/^[<blank><tab>]*$/d' textfile | sed -n -e '$p'