The UNIX and Linux Forums  

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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-07-2006
Registered User
 

Join Date: Jun 2006
Posts: 35
Stumble this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-07-2006
Registered User
 

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

http://www.student.northpark.edu/pem...d/sed1line.txt
Reply With Quote
  #3 (permalink)  
Old 09-07-2006
Registered User
 

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

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

hope this may help you.
Reply With Quote
  #4 (permalink)  
Old 09-07-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
awk ' {
if( $0 == "" )
prev_blnk = 1;
else
{
if ( prev_blnk == 1) { print "\n" $0 }
else { print $0; }
prev_blnk = 0;
}
}' file
Reply With Quote
  #5 (permalink)  
Old 09-07-2006
Registered User
 

Join Date: Jun 2006
Posts: 35
Stumble this Post!
Perfect. Thanks anbu23.

Regards,
-T
Reply With Quote
  #6 (permalink)  
Old 09-08-2006
Registered User
 

Join Date: Aug 2006
Posts: 122
Stumble this Post!
in UNIX uset cat

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

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

you can also try this

cat -r file1 >file2
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0