Use either one of both next commands with sed 's/to_replace/replace/': sed 's/ *$//' file sed 's/[[:blank:]]*$//' file
//Use this sed -e '/[[:space:]]\+$/s///' fileName.txt > FileName.temp //The temp file will allow you to check for spaces