Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save David7ce/9837fd7f78054d7748eca9e3df1d2daf to your computer and use it in GitHub Desktop.
Save David7ce/9837fd7f78054d7748eca9e3df1d2daf to your computer and use it in GitHub Desktop.
remove all blank lines using regular expressions

REGEX remove blank lines:

FROM: http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/remove_blank_lines.html


FIND:

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

REPLACE:

[LEAVE THIS EMPTY BECAUSE YOU DO NOT WANT TO REPLACE WITH ANYTHING]

(Related: If you happen to be where you can use AWK, you can use awk NF.
If you happen to be where you can use SED, you can use sed /^$/d' --
EXAMPLE USE OF SED sed /^$/d < text_with_blanks.txt > no_blanks.txt.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment