In passing: the `sed` I have immediate access to doesn't seem to support `\x20`, so I can't test it, but if you change: ``` sed -z -i 's/\x20\x0A/\x0A/g' "$f" ``` to: ``` sed -z -i 's/\x20\x20*\x0A/\x0A/' "$f" ``` or perhaps (which I have tested): ``` sed -z -i 's/ *$//' "$f" ``` I suspect you wouldn't need to make multiple passes for lines with more than one trailing space.