LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2007, 03:26 AM   #1
bharatbsharma
Member
 
Registered: Oct 2007
Posts: 33

Rep: Reputation: 15
replacing blank lines


Generally ppl talk about deleting blank lines frm a file but i want replace 'single blank line ' by 'double or more blank line'
 
Old 10-25-2007, 03:48 AM   #2
ehawk
Senior Member
 
Registered: Jul 2003
Posts: 1,257

Rep: Reputation: 48
Here is a suggestion using perl:

http://www.unix.com/unix-advanced-ex...ines-file.html
 
Old 10-25-2007, 06:17 AM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Are you sure this too shouldn't be done using awk? What did your teacher specify?

The pseudo code in awk may go like this.

For each line.
-- If the length is 0, then write the line and one more new line.
-- Else Write the line.]

End
 
Old 10-25-2007, 07:13 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
awk '/^$/{print "\n\n";next}1' "file"
or
Code:
awk '/^$/{print;print;print;next}1' "file"

Last edited by ghostdog74; 10-25-2007 at 07:14 AM.
 
Old 10-25-2007, 07:24 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
This will add another blank line using sed:
sed -i '/^$/i\
> ' test
 
Old 10-25-2007, 08:44 AM   #6
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Code:
awk 'ORS=NF?"\n":"\n\n"' filename
Add more \n after the semicolon if you wish.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing a bunch of lines between a pattern Namachivayam Programming 1 05-21-2007 07:23 PM
Replacing multiple lines with null aress Linux - General 3 03-06-2007 08:47 AM
Replacing new lines (\n) from a file bkeeper Linux - Software 4 12-15-2005 02:13 AM
replacing specific lines in a text document stellarmarine1 Linux - General 1 09-07-2004 02:34 PM
Replace blank/almost blank lines in file Wynd Linux - General 3 01-27-2004 04:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration