The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
make multiple line containing a pattern into single line VTAWKVT Shell Programming and Scripting 13 12-04-2008 06:40 PM
Reading multiple lines as single braindrain Shell Programming and Scripting 9 10-18-2006 10:16 AM
replacing first line or lines in a file Terrible UNIX for Advanced & Expert Users 3 06-28-2006 08:23 PM
Splitting a single line into multiple lines thanuman Shell Programming and Scripting 4 02-23-2005 04:56 AM
replacing multiple lines ajnabi Shell Programming and Scripting 1 04-09-2002 06:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2008
siba.s.nayak siba.s.nayak is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 164
replacing multiple lines with single line

Can any one give me the idea on replacing multiple blank lines with a single blank line?

Please conside it for a file having more than 100 number of characters.

Regards,
Siba
  #2 (permalink)  
Old 05-27-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
If you have that option with cat:
Code:
cat -s
With sed:
Code:
sed '/./,/^$/!d'
  #3 (permalink)  
Old 05-28-2008
siba.s.nayak siba.s.nayak is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 164
In my machine cat -s do nothing. The output is same as simply cat.

Te second one is doing fine in linux machine but not in HP-UX (When the no of characters in the line is more, say 1000 ).




Quote:
Originally Posted by ripat View Post
If you have that option with cat:
Code:
cat -s
With sed:
Code:
sed '/./,/^$/!d'
  #4 (permalink)  
Old 05-28-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
I don't have a HP-UX box to test but try any of the following:
Code:
 # delete all CONSECUTIVE blank lines from file except the first; also
 # deletes all blank lines from top and end of file (emulates "cat -s")
 sed '/./,/^$/!d'          # method 1, allows 0 blanks at top, 1 at EOF
 sed '/^$/N;/\n$/D'        # method 2, allows 1 blank at top, 0 at EOF

 # delete all CONSECUTIVE blank lines from file except the first 2:
 sed '/^$/N;/\n$/N;//D'
From: http://www.student.northpark.edu/pem...sed1line52.txt
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0