Find all duplicates

^(.*)(\r?\n\1)+$

Remove all blank lines

^(?:[\t ]*(?:\r?\n|\r))+

Trim leading whitespace:

^\s+

Trim trailing whitespace:

\s+$