Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting only two blank lines

Status
Not open for further replies.

NTOldTimer

Programmer
Jun 26, 2003
243
US
I have text files that get created with multible blank lines that I'd like to get rid of. I can use the regular expression ^$ to identify a blank line and delete them all but really I'd just like to delete blank lines only if there are two of them together. Is there a regular expression I can write that will identify two blank lines together and delete only one of them?
 
Hi

You mean, 2 or more consecutive empty lines to be reduced to 1 empty lines ?
Code:
perl -pe '$b=0if/./;$_=undef if$b++>1' /input/file

[gray]# or[/gray]

perl -ne '$b=0if/./;print if$b++<2' /input/file

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top