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
strip first 4 and last 2 lines from a file using perl meghana Shell Programming and Scripting 10 02-01-2008 09:01 PM
Read lines till a blank line is encountered saurabhsinha23 UNIX for Dummies Questions & Answers 1 12-19-2007 04:26 PM
delete blank lines from a file sachin.gangadha UNIX for Dummies Questions & Answers 2 12-04-2007 07:13 PM
Delete blank lines at the end of file TL56 Shell Programming and Scripting 3 10-25-2007 03:44 PM
Blank Lines - End of file saabir Shell Programming and Scripting 4 07-15-2003 11:55 AM

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 09-07-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Thumbs up Strip one line from 2 blank lines in a file

Hi
Is there any command to scan thru a file looking for 2 consecutive blank lines and if any remove one of them. Please let me know.

Regards,
Tipsy
  #2 (permalink)  
Old 09-07-2006
ahtat99 ahtat99 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 41
I think the website below has what you are looking for

http://www.student.northpark.edu/pem...d/sed1line.txt
  #3 (permalink)  
Old 09-07-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
"sedscpt" file contains
/^$/{
:nxt
n
/^$/!{x;p;x;}
$ {/^$/p;}
/^$/b nxt
}

sed -n -f sedscpt -e "$ {/^$/p;}" file

hope this may help you.
  #4 (permalink)  
Old 09-07-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
awk ' {
if( $0 == "" )
prev_blnk = 1;
else
{
if ( prev_blnk == 1) { print "\n" $0 }
else { print $0; }
prev_blnk = 0;
}
}' file
  #5 (permalink)  
Old 09-07-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Perfect. Thanks anbu23.

Regards,
-T
  #6 (permalink)  
Old 09-08-2006
Andrek Andrek is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 122
in UNIX uset cat

# cat -r filename
the -r will only display one blank line for every consecutive blank lines it finds...
  #7 (permalink)  
Old 06-23-2008
vinsin55 vinsin55 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 1
strip one line from 2 blank lines in a file

you can also try this

cat -r file1 >file2
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 09:32 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