Clean trailing whitespace with sed

Published: · Modified: · d2f29ce

Hi. This is just a short post; but I am still alive! :) I have recently cleaned up my neovim config, and I had the requirement for a script which cleans trailing whitespace. I have come up with some cool sed stuff. Here is my short script:

#!/bin/sh

sed '
    :a
    /^\n*$/ {
        $d
        N
        ba
    }

    s/[[:space:]]\+$//
' $@

Here are some links about this topic:

That’s it for today!