Getting a text file rid of all superfluous blank lines

John Summerfied debian at herakles.homelinux.org
Wed Nov 30 15:47:02 UTC 2005


Paul Smith wrote:
> On 11/30/05, Tim <ignored_mailbox at yahoo.com.au> wrote:
> 
>>>Taking a text file, how can one eliminate at once all superfluous
>>>blank lines?
>>
>>I used to know of something that did that (something with various
>>different reformatting options for massaging text files), but I can't
>>think what it was.  Quickly looking at the man file for the cat program,
>>you could do something like:
>>
>>cat --squeeze-blank inputfilename -> outputfilename
> 
> 
> Thanks, Tim and Paul. Paul's method does not mysteriously work:
> 
> $ more file1.txt
> word1
> 
> 
> 
> word2
> 
> word3
> $ more -s file1.txt > file2.txt
> $ more file2.txt
> word1
> 
> 
> 
> word2
> 
> word3
> $
> 
> Tim's way works partially, i.e., many blank lines are in effect
> erased, but some remain. I suspect that the left blank lines are not
> blank lines although they look like blank lines. Can one go further
> with deleting the left "false" blank lines?
> 
> Paul
> 
man tr
You may have some tabs.
You might also need to remove consecutive blanks in which case
man sed
and maybe
man regex

-- 

Cheers
John

-- spambait
1aaaaaaa at computerdatasafe.com.au  Z1aaaaaaa at computerdatasafe.com.au
Tourist pics http://portgeographe.environmentaldisasters.cds.merseine.nu/

do not reply off-list




More information about the users mailing list