Home » Support » Tutorials/Power Tips » UltraEdit » Remove blank lines

IDM PowerTips

Remove blank lines

A question which users frequently have is: "I have a lot of blank lines in my file and I don't want to go through and manually delete them. Is there an easier way to do this?"

The answer: YES!

In versions of UltraEdit that support Perl style regular expressions, you can use the following Perl regex in DOS/Unix/Mac formatted-files. You can enable Perl style regular expressions by clicking the "Advanced" button in the Find dialog to show the Advanced search options, or prior to UltraEdit v14.00 enable Perl compatible Regular Expressions under Advanced -> Configuration -> Search -> Regular Expression Engine.

Find What: "^(?:[\t ]*(?:\r?\n|\r))+" (without the quotes)
Replace With: "" (without the quotes - i.e., nothing).

Note: A single Replace All with this Perl regular expression search string is enough to replace even consecutive blank lines.


Removing blank lines in previous versions (non-Perl regex)

In previous versions of UltraEdit, to delete blank lines you can use a regular expression replace as follows: Find What: "%[^t ]++[^r^n]+" (without the quotes)
Replace With: "" (without the quotes - i.e. nothing).


Step 1: Determine the file(s) that contain blank lines


Step 2: Open the Replace dialog

You may open the replace dialog using the shortcut (CTRL + R) or by going to the search menu and clicking on "Replace".

To delete blank lines you can use a regular expression replace as follows:

Find What: "%[^t ]++[^r^n]+" (without the quotes)
Replace With: "" (without the quotes - i.e. nothing).

Note: You MUST select "Regular Expressions." Also, "UltraEdit style expressions" must be selected under Advanced -> Configuration -> Search -> Regular Expression Engine.

Depending on your circumstances, the "Replace Where" option you select may vary.

Note: For Mac formatted-files not converted to DOS on load the UltraEdit regular expression find string must be "^r[^t ]++^r" and the replace string "^r" (both without the quotes).


Step 3: Your blank lines are gone!

Please note, you may have to run the "Replace All" multiple times to ensure all blank lines are removed. Because of the way the regular expression works, the replace will not replace all blank lines that are grouped together.