//Use this sed -e '/[[:space:]]+$/s///' fileName.txt > FileName.temp //The temp file will allow you to check for spaces