Removing blank lines in text file using Regular Expression

This tutorial explains about the removing blank lines using regular expression. Here I have used the TextPad Editor to do this.

For Example, the contents of the file is as follows , with lot of blank lines. We will see how we can remove this using TextPad

image001

Select Search -> Replace or F8 (keyboard shortcut)

image003

Select the option shown below, in the “Find what” field enter “^\n” (without the quotes), and then click on “Replace All” button.

image005

This screenshot shows the final outcome of the text file.

image007

Final Note:

What does the “^\n” mean ?

In regular expression “^” indicates the start of the line, “\n” is end of line,  so “^\n” is that any line starting new line character , replace with blank character.

About these ads

3 thoughts on “Removing blank lines in text file using Regular Expression

  1. Nvaeen July 10, 2013 at 6:55 am Reply

    Thank you for ur tips.. :)

  2. peter August 24, 2013 at 3:21 pm Reply

    thank you!

  3. Sree November 19, 2013 at 4:07 pm Reply

    Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: