Get rid of whitespace on otherwise empty lines

Retina, 5 bytes

%G`\S

Try it online!

A not so obvious approach rewards us with a better score :)

Explanation

G indicates this as a Grep stage, keeping only those lines where a match to the regex given (\S, matches non-space characters) can be found. If it wasn't for the starting % this would completely remove lines instead of just "emptying" them.

The % is a modifier which applies the stage once to each line and then joins the results with newlines: in our case this means that the empty string returned by Grep for whitespace-only lines will become an empty line in the result.


sed, 6 bytes

/\S/!g

Try it online!

/  /!  # If the line doesn't contain...
 \S    # anything non-whitespace (i.e. the entire line is whitespace)
     g #   replace the pattern space with the hold space which is empty

Japt, 10 8 6 5 4 bytes

mx1R

Try it online!

Explanation

(from the Japt docs)
.m(f,s=""):
Splits this with s, maps each item by f, then rejoins with s.

So mx1R splits the string by R which is a newline, trims the right hand side of each line using x1 and joins the strings again with a newline.

Saved 2 bytes thanks to ETHproductions.