in reply to When is a trailing space not a trailing space?

bluto sort of suggested this already. For human readable files (not binary/data/etc) this should be a good fix and can be used in other places too.

s/[^[:print:]]+\z//;