perl -i -0777pe's/\n+\z/\n/' /tmp/file.txt