Removing Trailing Line

I have been trying to remove empty lines and lines just filled with spaces. I have used the following command which does work.

sed -i "/^\s*$/d"

Except it leaves one single trailing line at the very end of the file. For the life of me I cant figure out why I cant remove that last trailing line. It appears to be a line feed character as the hex code is "0A".

Anyone have any ideas how to remove it? I don't care if I need to run a second command after my first SED command to get rid of it.

Hello,

You can awk , grep etc for same.
Following may help you.

1) awk '/^$/ {next} 1' filename
 
2) grep -v '^$' filename
 
3) sed '/^$/d' filename

These above commands will remove the lines which are empty in file.

Thanks,
R. Singh

The 0a is the end of the last line - not another empty line!
Unix text files without the 0a are incomplete: tools like sed,grep,awk might behave oddly, or silently add the missing 0a.