Wednesday, September 12, 2007

totally squeezed out multiple blank lines

Well, just popped out from my mind based from privious linux blog entry.

Have you ever tried editing a thousand lines of configuration file and 70% of the lines were commented? Yes, you can filter out the commented lines using grep, but what about totally removing multiple blank lines between each config line?

Here's a quick way on how to remove all blank lines from a file using strings linux command.

A sample readable text file.

# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is a long line of words that is useless for now.This file is an example of human readable text file.






I am going to paste this file into my Linux SysAd blog! This is a long line of words that is useless for now.This file is an example of human readable text file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To squeezed out and remove multiple or all blank lines from the text file using string linux command would be like so

# strings testfile.txt
EDITED:
# strings -n 1 testfile.txt

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a long line of words that is useless for now.This file is an example of human readable text file.
I am going to paste this file into my Linux SysAd blog! This is a long line of words that is useless for now.This file is an example of human readable text file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EDITED:
# strings -n 1 testfile.txt


HTH

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy